out of memory...weird problem help pls!

kennis

New member
Joined
Mar 4, 2005
Messages
4
Programming Experience
Beginner
hi guys, hope someone can help me.
i got a webcam which takes 2 snapshots per second (every 500ms take the snapshot) and overwriting the same file .jpg
i got a algorithm which get the image from file every 800milliseconds.
sometimes less than one minute the error out of memory shows.
I figured out that the memory is not actually out, since i was watching the memory available in task manager.
I tried to work this algorithm without the webcam, i mean reading the same image every 800ms and it never run out of memory.

Dim fileName as string
Dim pimage as Image;
fileName="c:\photo002.jpg";
if (File.Exist(fileName))
pimage=Image.FromFile(fileName); 'out of memory line (i did only a try catch with this line in specific and the problem shows here)
...do something
pimage.dispose();
End if


Thanks for help!
 
Try diming pimage as a global and don't dispose it. That way it should reuse the same memory block.

TPM
 
Hmm maybe it's trying to open it while the camera is still writing...
That would explain why it works if you turn the camera's capture off.
Try checking if the pic. is open first.

TPM
 
i got this:
this is from the MSDN
Remarks
The file remains locked until the Image object is disposed.
If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception.

what can i do a condition if (...) if the condition is good so asign to the image.
 
You know it's not the image/pixel format as it works if you turn the update off, and it works for some time before crashing. I'd say that the file probably doesn't have time to lock.
 
well i already resolve the problem, i did a try catch in the error line, if the error is been catch i return the function so the system would continue working normally.
i have my last question i have a timer tick for every 500ms and do something,
if the process take more than 500ms, the timer_tick will continue do the next process (and cancel the current process) or it will process two actions in the same time?
 
I belive the second won't fire untill the first has finished. If you wanted they to run at the same time you'd been to use multi threading.

TPM
 
Back
Top