I was writing a program for capturing the screen at a set interval and when I started testing, I found that I get an OutOfMemoryException almost immediately after it starts capturing pictures. I tried allocating more memory – I gave it 256m, but that hardly helped. All that it did was make it last 2 or 3 more seconds before throwing the exception and crashing again.
I understand that the createScreenCapture(…) method uses a lot of memory, but I have seen example programs that can record for long amount of times using the same method – how do they do it?
Edit: I’ve used some of your guys’ advice and now I don’t get OutOfMemoryExceptions! Hooray! I took the route that involves saving the photos to the hard drive. However, actually writing them to an archive file does take quite a long time. Writing 63 frames into an archive file takes almost 2 minutes!
I can’t provide any code because I’m rewriting the I/O part. Working on improving the ^ situation.
Serialize the images to disk (as separate files or into a single Zip).
There are a number of strategies that can be pursued.