View Single Post
  #5   Spotlight this post!  
Unread 03-07-2016, 07:29 PM
jkoritzinsky jkoritzinsky is offline
Registered User
AKA: Jeremy Koritzinsky
FRC #4786 (Nicolet F.E.A.R.)
Team Role: Mentor
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Glendale, Wisconsin
Posts: 78
jkoritzinsky will become famous soon enoughjkoritzinsky will become famous soon enough
Re: WPILIB Camera Code Crashing JVM

Quote:
Originally Posted by pblankenbaker View Post
Not sure if this is related or not to your issue, but we had a problem with exhausting memory when grabbing images that would cause the robot code to crash and burn after running for a certain time period.

We found a fix (or work around) by invoking the free() method on the image objects returned after we were done with the image. The following provides an idea of what we did.

Code:
    // Grab image from USB camera and push out to camera server
    // for smart dashboard display
    Image frame = NIVision.imaqCreateImage(ImageType.IMAGE_RGB, 0);
    usbCamera.getImage(frame);
    cameraServer.setImage(frame);

    // Program crashes with out of memory issue if we remove this line
    frame.free();
I'm not really sure if calling free() is required on image objects (in Java you would hope that resources would be automatically freed by the garbage collector), I just know that our problem went away once we started invoking free().

Again, not sure if this is related to the problem you are seeing (I didn't see anything in your error messages about running out of memory), but it might be something to try.

Good luck.
In Java, the only resources released by the GC is GC-managed memory. The free call might be needed because if there are non-Java (C/C++/LabVIEW/files/etc.) resources held within an Image object, they will not be freed by the GC. This problem is the rationale for the try-with-resources (Java 7+). C++ has RAII to prevent this from ever being a problem.
__________________
Nicolet F.E.A.R. (Team 4786) - Aerial Assist - Programming Manager
Nicolet F.E.A.R. (Team 4786) - 2015+ - Junior Mentor

SuperScouter for FRC Developer
Reply With Quote