i am using java application . in this application capture image from webcam using jmf and java after capture 4 or 5 images its goes to video mode. i cant to capture image again at that time showing some error "heap error out of memory exceptions" please any one tell me idea. Advance in thanks
Asked
Active
Viewed 1,473 times
-2
-
1We need to see your code. *Out of memory* can occur when there's a major memory leak in you application. – FThompson Nov 06 '12 at 16:11
-
What are you doing with the captured images? Are you writing each frame to memory? If so, when do you free memory? Can you post some of your code to give an idea of where you're having trouble? – Cliff Nov 06 '12 at 16:11
-
1There is one non-obvious spot in BufferedImage, `BufferedImage.createGraphics()` needs a `dispose()`. – Joop Eggen Nov 06 '12 at 16:27
1 Answers
0
First check if you are calling dispose()
on Graphics2D
created via BufferedImage.createGraphics()
, then check if you are calling flush()
method on BufferedImage
you have created when you do not want to use this image any more. If this won't help, you can try to use ready solution, e.g. utilize this project:
https://github.com/sarxos/webcam-capture
Code example (take picture from webcam and save in test.png file):
Webcam webcam = Webcam.getDefault();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "PNG", new File("test.png"));
With this library you don't need to dispose graphics nor flush buffered image after it is not used any more - underlying driver will do it for you.

Bartosz Firyn
- 2,664
- 2
- 21
- 18