Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Java, WPI, Image Processing, and OMG I got a memory leak... (http://www.chiefdelphi.com/forums/showthread.php?t=113460)

Team3266Spencer 13-02-2013 23:02

Java, WPI, Image Processing, and OMG I got a memory leak...
 
I created the targeting code for our robot today. Everything was working great until about 20 seconds in ... WHAM! Out of memory... I'm pretty sure I freed both the BinaryImage I used and the ColorImage I used correctly. Please don't tell me this is a memory leak in the WPILibJ because targeting will be impossible since all the code is precompiled for Java and would be extra-tricky to change.

Ginto8 14-02-2013 06:06

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
You may not be running into a memory leak, but instead memory fragmentation. To minimize the number of (re)allocations done, you can try something like this:
Code:

// Inside the class, outside of any methods
Image image = new RGBImage();
BinaryImage bin = new BinaryImage();

Then later:
Code:

camera.getImage(image);
NIVision.colorThreshold(bin.image, image.image, ... );
// Other processing ...


Team3266Spencer 14-02-2013 10:03

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
Thank you for a positive response, Ill try this when Im with the robot next. I am curious though, is this how you do your targeting?

Ginto8 14-02-2013 22:24

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
I used that technique last year to minimize memory consumption, but this year our tracking software is running as a SmartDashboard extension.

F22Rapture 15-02-2013 00:31

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
Just a notice that the SmartDashboard v1.05 revision is up as of a few hours ago, and it solves several issues with the vision plugin.

I'm not sure if that would help you (it sounds like you're doing it robot-side?) but it may help others.

Team3266Spencer 15-02-2013 07:53

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
I don't want the delay of the data transfer, but thank you for that wonderful news. I hope it fixes the SmartDashboard crashing bug.

Team3266Spencer 16-02-2013 12:44

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
What do I do about the exception handling?

Arhowk 16-02-2013 17:54

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
Quote:

Originally Posted by Team3266Spencer (Post 1234348)
What do I do about the exception handling?

try{
//
}catch(SomethingException ex){
ex.printStackTrace();
}

Team3266Spencer 16-02-2013 22:35

Re: Java, WPI, Image Processing, and OMG I got a memory leak...
 
You can't put try statements outside of a method. I found that simply creating the image objects outside of a method fixed my memory issues, I did not need to initialize them outside the method or call methods from NIVision. Thank you for the help Joe.


All times are GMT -5. The time now is 10:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi