Using Camera API requires too much memory
| Tue, 2007-10-23 00:45 | |
|
|
Hi there, I have a "small" problem with my N95 and using the camera on it. Briefly my problem is that my application quits after taking the first few (say, 6) photos, which is undesirable, especially considering the fact that I'd like to take a lot of photos in succession. I'm not sure if it counts, but for your information the image resolution is the highest (2592x1944 == 5M) with EXIF as image format. The problem is that I have only 17 megs of free memory on my device right after start-up and whatever I do in my camera-enabled program, it always consumes at least 5-6 megs from free memory (thus only 11 megs remains). For example, I took HelloWorldBasic example program from the SDK and added a very simple new class to it that just instantiates CCamera object in ConstructL and deletes it in the d'tor. Only this simple addition changed the appetite of my program so that it requires 5-6 megs of memory instead of its previous memory footprint, that is, around a few 100k. Another thing I've noticed is that it takes more and more memory when I take photos in succession (so that amount of free memory is getting less). For example, I can usually take 4-6 photos before my program quits. And that is not an accident: I've observed that it takes ~100k per photo from free memory despite the fact that I don't store them in any arrays, I just simply write each into a file and forget about it. I'm under the assumption that the amount of free memory reaches a critical level and Symbian OS's memory watchdog forcefully shuts down less important applications, such as mine. Forcefully, I say, that is, my program does not panic or crash, it just quits without any error. The thing I've observed, too, that this sample program (provided by Nokia, btw) works similarly on a range of S60 3rd Edition devices, such as N73, N80. I've even tried it out on another N95 using Nokia RDA (Remote Device Access) - with the same results. Interestingly (or not), the figures regarding how much memory remains after app start-up change from device to device, nevertheless it still allows me to take only 4-6 photos before quitting. I've also observed that the built-in camera consumes less memory upon start-up and frees some memory up while taking the photos. Needless to mention that it doesn't quit. Weird. The last thing I think is worth sharing with you is that I have a similar application written in Python for S60: it also uses camera and takes photos one after the other. I've checked it out and found that launching Python run-time takes 1-1.5 megs and my program also requires another 5-6 megs from free memory (similarly its "Symbianish" counterpart). The odd thing, though, is that the program has never crashed, although I took dozens of photos and even reached a very (I mean, very-very) critical level of memory, when there was only 3.8 megs of free RAM. And even in this critical situation did Python framework and my program work smoothly without any problems. After closing the application manually and exiting from Python shell did the system get about 10 megs back. After this long story, I'm sure you all know what I'm asking from you: have you ever experienced such an odd behavior with regards to the (Symbian) Camera API? Did you find any solution? Can you suggest me anything you can think of would be useful to achieve my goal (i.e. be able to take lots of high-quality photos in succession)? Looking forward to hearing from you soon! Tote Gabor Torok |






Forum posts: 40
Do you free the memory buffers after saving images? It is up to the application to delete HBufC8* aData object that is returned by MCameraObserver::ImageReady() call back.
Forum posts: 723
Yes, as I have mentioned I don't keep track of images taken in terms of storing them in an array. I always free up the previous image buffer before saving the current one. And there's no orphaned heap cell, either.
By the way, this is the example application that I was referring to so far. I should have added this link earlier.
Any help?
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 723
Breakthrough, I've got the solution!
My program was leaking memory (as well as the example program) and it was due to incomplete API specification and an improperly written example application. If you have a look at MCameraObserver::ImageReady(...) method you can see that nothing is mentioned as to the ownership of objects (aBitmap, aData) being handed over to the caller. But it is. The sample program was improperly written:
void CCameraCaptureEngine::ImageReady(CFbsBitmap* aBitmap, HBufC8* aData, TInt aError) { ... if ( iImageExif ) { delete iImageExif; iImageExif = 0; } iImageExif = aData->Alloc(); ...whereas it should look like this:
void CCameraCaptureEngine::ImageReady(CFbsBitmap* aBitmap, HBufC8* aData, TInt aError) { ... if ( iImageExif ) { delete iImageExif; iImageExif = 0; } iImageExif = aData; ...Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/