memory leak

Eduard

Active Member
Licensed User
Hi,

My App has memory leaks. I discovered that memory usage goes up when I just open and close an activity (any of them). If I repeat that, memory goes up and up.

After a while memory usage is going down (I guess this is the garbage collector).

However, it never goes back down to the original level. So I assume the garbage collector could not remove everything! Yesterday I found some way to really get it up and I got an out of memory error. (>128 Mb usage!)

I made some changes that made a difference:

1) I stopped starting the activity used for taking pictures with an intent flag FLAG_ACTIVITY_CLEAR_TOP

(How) can this be of influence? :sign0163: I don't understand.

2) I found a stream in my service to upload pictures that was not properly closed.

Should all streams be closed? I still see that an outputstream in HttpJob.Postfile isn't closed. In CameraExClass.PreviewImageToJpeg is another stream that is not closed.


My question is: Where (else) should I look? I wasn't able to go into out of memory today, but I got it really high after taking about 20 pics of 4 megabytes and upload them. I still believe there is another leak.

I read this :
Activity objects cannot be declared in Sub Process_Globals (as this would cause a memory leak).

I am using some activity object in code modules, these are called from classes. I first put them into the class, but then I got an error that class isn't an activity context. The activity object is called in a code module, which is called from a class modules, which is in a list of another class of a list that is a proces global.

Can the leak be related to this?
 
Last edited:

Erel

Administrator
Staff member
Licensed User
1) I don't think that it is related.

2) Streams should be closed when they are no longer used. Memory streams, like used in HttpJob.PostFile doesn't do any harm if not closed as the memory will be freed when the garbage collector releases this object.

In most cases images are the cause of large memory consumption. It is hard to say what causes the issue in your application without seeing the code.

Also note that if there is a memory leak then eventually you should get an out of memory error. If you do not encounter such an error (after you update your code) then it is likely that there is no leak.
 
Upvote 0

Eduard

Active Member
Licensed User
Thanks,

Since the changes it is really hard to get an out-of-memory error, but it is still possible. There must still be a leak, although small.

Could it be that the leak is because I call a module dialog (which contain activity objects) from a code module that is called from a class, that is in a list of process global list?
 
Upvote 0

Eduard

Active Member
Licensed User
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:nl.connectapp.connect
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (s_main) Create **
** Service (s_main) Start **
** Activity (main) Pause, UserClosed = true **
** Activity (a_groepen) Create, isFirst = true **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = true **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
startService: class nl.connectapp.connect.httputils2service
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
90
** Activity (a_camera) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = true **
** Activity (a_groepen) Create, isFirst = false **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_groepen) Create, isFirst = false **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_groepen) Create, isFirst = false **
** Activity (a_groepen) Resume **
** Activity (a_groepen) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Create, isFirst = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
0
** Activity (a_camera) Pause, UserClosed = true **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = true **
** Activity (a_contacten) Resume **
** Activity (a_contacten) Pause, UserClosed = false **
** Activity (a_contact) Create, isFirst = false **
** Activity (a_contact) Resume **
** Activity (a_contact) Pause, UserClosed = false **
** Activity (a_camera) Create, isFirst = false **
** Activity (a_camera) Resume **
s_main_threadx_verstuur (java line: 1142)
java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java:432)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:642)
at java.lang.StringBuilder.toString(StringBuilder.java:663)
at anywheresoftware.b4a.keywords.StringBuilderWrapper.ToString(StringBuilderWrapper.java:57)
at nl.connectapp.connect.s_main._threadx_verstuur(s_main.java:1142)
at nl.connectapp.connect.s_main._threadx_ended(s_main.java:914)
at nl.connectapp.connect.s_main._thread0_ended(s_main.java:790)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA$3.run(BA.java:303)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Installing file.
 
Upvote 0
Top