Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory error when using multiple cameras #77

Closed
FlyingLotus1983 opened this issue Feb 4, 2015 · 10 comments
Closed

Out of memory error when using multiple cameras #77

FlyingLotus1983 opened this issue Feb 4, 2015 · 10 comments
Labels

Comments

@FlyingLotus1983
Copy link
Contributor

I'm getting an out of memory error for some reason, thinking it might have to do with multiple cameras. I initially had a 90 degree rotation on C1, but the memory error happens if set to zero (which I assume bypasses the rotation code?).

When disabling one camera or the other camera, the system seems to work as expected.
With both cameras enabled, it will eventually freeze with the error below.. the time-to-freeze varies, but is never more than a few minutes.

Exception in thread "Thread-4" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:76)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:266)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:384)
at org.openpnp.util.OpenCvUtils.toBufferedImage(OpenCvUtils.java:43)
at org.openpnp.machine.reference.camera.OpenCvCamera.capture(OpenCvCamera.java:68)
at org.openpnp.machine.reference.camera.OpenCvCamera.run(OpenCvCamera.java:86)
at java.lang.Thread.run(Thread.java:745)

My machine.xml is posted here:
https://gist.github.com/FlyingLotus1983/51747c6de78558836a9d

@FlyingLotus1983
Copy link
Contributor Author

I've never troubleshooted a Java memory error, so I'm not really sure where to start. So far the Oracle docs aren't that much of a help.

@FlyingLotus1983
Copy link
Contributor Author

At Jason's request, I tried adding -Xmx1024m to the JVM options, which increases the available memory to the process.

Still dies with 2 cameras.
Never, ever dies with 1 camera.
Still investigating and checking code for potential problems that could cause this.

Oh, this is a Windows issue BTW :)

@vonnieda vonnieda changed the title Out of memory error when using mulitple cameras Out of memory error when using multiple cameras Feb 4, 2015
@FlyingLotus1983
Copy link
Contributor Author

I will give this a try tonight, thanks!!

@vonnieda
Copy link
Member

vonnieda commented Feb 4, 2015

Good catch. I didn't realize they had to be manually released. If that's
the case then this is definitely a memory leak. I'm surprised the library
doesn't handle that with a finalizer though.

On Wed, Feb 4, 2015 at 6:06 AM, Neil Jansen notifications@github.com
wrote:

I will give this a try tonight, thanks!!


Reply to this email directly or view it on GitHub
#77 (comment).

@vonnieda
Copy link
Member

vonnieda commented Feb 4, 2015

If this works, it can actually be simplified. Just release the Mat after
calling OpenCvUtils.toBufferedImage(capMat).
OpenCvUtils.toBufferedImage(capMat)
copies the data out of the Mat, so there is no need to have it afterwards.

On Wed, Feb 4, 2015 at 8:03 AM, Jason von Nieda jason@vonnieda.org wrote:

Good catch. I didn't realize they had to be manually released. If that's
the case then this is definitely a memory leak. I'm surprised the library
doesn't handle that with a finalizer though.

On Wed, Feb 4, 2015 at 6:06 AM, Neil Jansen notifications@github.com
wrote:

I will give this a try tonight, thanks!!


Reply to this email directly or view it on GitHub
#77 (comment).

@vonnieda
Copy link
Member

vonnieda commented Feb 4, 2015

The capture theretically should return rectified Mat.

Can you explain further? I don't understand what you mean by this.

FlyingLotus1983 added a commit to firepick-delta/openpnp that referenced this issue Feb 6, 2015
@vonnieda
Copy link
Member

@FlyingLotus1983 Is this issue still valid? I see you had committed a fix. Are you using it, or are you using the stock code?

@vonnieda vonnieda added the bug label Jun 30, 2015
@FlyingLotus1983
Copy link
Contributor Author

I'll try to check and get back to you.. Don't think I ever submitted a pull request for it. Will investigate.

@FlyingLotus1983
Copy link
Contributor Author

OK, just looked into this, I had committed it to my old fork but never did a pull request. I just applied the diff and will send a pull request for this, just as soon as I finish getting eclipse running on my new machine.

@vonnieda
Copy link
Member

vonnieda commented Oct 4, 2015

This has been fixed for quite a while. The Mat is now released before the function returns.

@vonnieda vonnieda closed this as completed Oct 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants