Quote:
Originally Posted by Ether
Thanks for the detailed explanation.
The question still remains I guess: why did that "problematic allocation" cause the code to crash after an extended period of running?
It would be useful to understand exactly what's going on. Such understanding could provide Java teams with some guidance concerning memory allocation.
Java gurus?
|
In our previous C++ implementation, the main robot thread will free the image frame once it's done with it. But in Java, there is no "delete" object. Java relies on the garbage collector to automatically reclaim unused memory. I am not an expert in Java but my understanding is that garbage collection is a relatively expensive operation. It needs to scan references to objects to make sure an object has no reference before it can be reclaimed. Because of the expensive nature of the operation, garbage collector tends to run only when memory is running low (below a certain threshold). In our case, we are allocating image frame at processing rate (could be as fast as the video frame rate). I am guessing the garbage collector was not able to catch up by reclaiming enough memory for the allocation so the Java VM simply run out of memory and crashed.
In my personal opinion, I always don't like the fact that Java takes away the ability for programmers to explicitly free memory. Garbage collector to auto reclaim memory is nice but it doesn't have to take away the delete operator. I know why they did it but I don't agree with it.