Android Question camEx: memory problem when changing orientation

JordiCP

Expert
Licensed User
Longtime User
Hi,

I am using the Camera library and camEx class for an app I am developing. The app supports both landscape and portrait mode, so when i rotate my device the activity pauses, creates and resumes...everything ok

I had observed that each time I did it, I had less memory available in a Samsung Galaxy SII. I tried to read and follow all the stuff and good practices related to bitmap recycling and it was nearly solved, but still some memory was "lost" each time I rotated the device. I could not find where


I went back to the original camEx example, exactly as it is (only adding VBBitmap library in order to use its memory monitoring functions) and observed that, in a slighter way than in my app, but also if I rotated the device some times, the available memory is each time less.



What can it be due to? How can it be solved? is it possible that some reference to the view inside Panel1 is still hidden somewhere when the camera is released? I want to release this app supporting device rotation, but I don't dare to, since, even perhaps this doesn't happen in all the devices, I don't fell comfortable knowing it


Thanks
 

JordiCP

Expert
Licensed User
Longtime User
Hi Erel,

In fact, I am not sure about anything...everything is very strange

I modified the cameraEx example, just adding some memory tracking. Each time I rotate the device, the memory is less, but only very slightly. There can be small memory releases from time to time (i.e., not always decreases), but what it is sure is that after 20 changes of orientation (for instance), the memory is less. This happens in a Android 2.3 device, not in a 4.x

If this was the only thing, would not be a real problem for me, since the probability that there are so many changes of orientation is very small.



But, going back to the app I am developing, which uses the camEx library, my memory "went away" very quickly. So I started to remove things to isolate the problem , and what I got is very strange.

After removing most of the code, at the end I could reproduce the "bad" behaviour in a small code , with two non-overlapping panels: The first is used for the camera and the second for a canvas in which (in this example) i draw a circle. I attach the code

There are two global boolean variables which are only assigned when FirstTime=True, in this code I use them as some sort of compilation directives
USE_CAM (if True, we will init the cam and show the preview in Panel1)
USE_CANVAS (if true, we will draw a canvas on Panel2)

When USE_CANVAS=True and USE_CAM=False, -----> everything is ok, no memory is lost
When USE_CANVAS=False and USE_CAM=True, -----> only a bit of memory less each time, but I don't mind since it is very small, and I am not sure that perhaps it will recover later
But...
When USE_CANVAS=True and USE_CAM=True, memory gets lost more quickly after each rotation. If I keep on rotating, OOM appears



I have observed that the outofmemory errors come when the remaining memory is about to zero, not always at the same moment, but more or less.

(1)MaxMem: 6.7108864E7
(2)HeapSize:8331232 (Free: 3474576)
(4)NativeUsage: 9404080
FreeTotal (1)-(4) : 57704784
FreefromHeap (1)-(2-3)-(4):
51608.34375 (this is the number I monitor since when it decreases a lot is when OOM errors appear)


So, I am totally confused, since those things didn't happen on the other device I was developing. And both panels are totally independent.

I am about to release my app, and I had not paid attention to it at the beginning, and now I don't know what to do to solve it.


Please help. No ideas left
 

Attachments

  • proves.zip
    441.5 KB · Views: 182
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Oops sorry, I will do it!

Yes, I had changed it in a desperate intent. Have tried again with camEx.release and it works the same way...


The fact is that without camEx, all memory keeps ok after successive device rotation

Is there any way to solve it? I'm totally lost :(


Thank you!


Would it possible to get the java source for the current library version? I also would like to try to implement some features that I need for my app
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I understand, but I had to try ;) I wanted to experiment on doing some stuff internally with the preview data before it is drawn, while still having access to its features through B4A...don't know if it is possible


I have tested your suggest, and same results.

The example is really small, so there are no strange things there. Perhaps it is related to the android version, or other stuff, but in my case in can't get to make it work properly :confused:

Will try to make my app landscape only and change the view programatically based on device sensors


Thanks anyway!
 
Upvote 0
Top