Memory leaks, methods and tools to find?

Silentsea

Member
Licensed User
Longtime User
Hi,

after a long break of development I could now finish a first version of our b4a android app. Thanks for this wonderful framework. Testing the software I noticed some stability problems (not b4a part I think). I found some unexpected bugs. The app is loosing memory. First I thought a part of my picture drawing code was wrong but after breaking down parts of the software I noticed this behaviour in other parts too. Reading across some threads in this forum, I detected some posts in context of setting references to null, or using objects only local and recycle bitmaps etc.. I thought I do this most times, especially using objects local. But maybe I was misunderstanding some parts.

So here are some questions of mine:
  • Finishing activities: All references should be cleared, if a view belongs to this activity, and a object to this view?
  • Scrollview rebuilding: In some cases I have to rebuild a scrollviews whole structure, first I delete all views belonging to this global activitiy view. But what about the objects in this views beloning to this view before?
  • What tools can I us to detect my mem problem, in java forums I've read to use eclipse tools to detect my still referenced objects?
  • Other methods or tools you prefer, next writing clean code ;)?

I have to say, because of our design, I use a lot of images, all the bitmaps are initialized at startup (size will be upscaled, so I try to use little images). After then in activity create, I use setbackground to refer to this image.

Thanks in advance.
Silentsea
 

thedesolatesoul

Expert
Licensed User
Longtime User
[*]Finishing activities: All references should be cleared, if a view belongs to this activity, and a object to this view?
Yes, this is true as long as the object is not referenced elsewhere. However, it may not be cleared immediately, but only when the OS thinks it needs to clear it.

[*]Scrollview rebuilding: In some cases I have to rebuild a scrollviews whole structure, first I delete all views belonging to this global activitiy view. But what about the objects in this views beloning to this view before?
The objects you assigned to these views (like drawables,tags etc) can be cleared if the same object is not being referenced elsewhere. (For e.g. a drawable used as another views background which is still on the activity will not be cleared)

[*]What tools can I us to detect my mem problem, in java forums I've read to use eclipse tools to detect my still referenced objects?
I sometimes use DDMS to check whats happening with memory.
Using DDMS | Android Developers
Android Developers Blog: Memory Analysis for Android Applications


[*]Other methods or tools you prefer, next writing clean code ;)?
Try to use less globals and use variables in the scope you need, so you dont have too many references to variables you need to clear.

Thats just what I have learnt so far. Will be interesting to know what other developers do.
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
I sometimes use DDMS to check whats happening with memory.

I wanted to try it but I can not select the application, it appears only for a millisecond on my 3 devices.

Anyone who knows what the problem could be? Drivers should be correct. I tried to update.
 
Last edited:
Upvote 0

Tom Law

Active Member
Licensed User
Longtime User
I was wondering if my b4a code formatter would help you. Not only does it format your code (making it more readable) but also searches out dead code and unused variables. Do a search for 'B4a Source Code Formatter'. Its in the libraries section (its not a library its a vb program).

Tom
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Thanks, but I don't want to get my code more readable, maybe I will give it a try. But first I need to get ddms running. I've reinstalled android sdk, drivers, testet sample programs out of b4a but the same result ervery time: No app to select under my devices :BangHead: ! I shut down firewall and scanners too for my testing environment.

Need further assistance.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Thanks, but I don't want to get my code more readable, maybe I will give it a try. But first I need to get ddms running. I've reinstalled android sdk, drivers, testet sample programs out of b4a but the same result ervery time: No app to select under my devices :BangHead: ! I shut down firewall and scanners too for my testing environment.

Need further assistance.
Can you post a screenshot of the ddms window?
 
Upvote 0

Tom Law

Active Member
Licensed User
Longtime User
Just checked out your app. Love the graphics, pity I don't speak German it looks really professional.
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Sure
 

Attachments

  • ddms (2).png
    ddms (2).png
    91.8 KB · Views: 284
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I see.
It may be a USB Driver issue as well.

Also worth looking at the prerequisites mentioned here (although it is for something else): How to enable native heap tracking in DDMS « Bricolsoft Consulting


Also worth giving a shot to adding the following to the manifest (it will only show debuggable apps):
B4X:
AddApplicationText(android:debuggable="true")

Mine is probably working because I am using a CM9 rooted ROM.
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Oh man, I found a solution to see the client under my devices:

Make sure you have android:debugable="true" in you application tag in the manifest file.

After changing that in manifest file and setting the file to read-only it works.

Btw. is there a way to set this in b4a, so that the file will not be overwritten on next run? I think I've to give the manifest editor a further look.

Thanks for the moment.

Silentsea.

[thedesolatesoul, a little bit quicker ;), thanks ]
 
Last edited:
Upvote 0

Silentsea

Member
Licensed User
Longtime User
As I mentioned, I testet this on different devices running different roms (e.g. 3.2 for my samsung pt-p6800 (rooted)).

I've to read the tutorial of the manifest editor also for adding android:theme="@android:style/Theme.Translucent" to activities, if it will be possible. But this ins't topic of this thread.

Now I will try to find my mem leaks with ddms.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
For me, no success with my two devices. I can see their files with the DDMS explorer. I can take screenshots and see the events, but that's all.
Do you see any processes under the device in the devices tab/tree?
Click on the process you want to monitor and then 'Show heap updates' in the toolbar. Then in the VM Heap tab you should see things change in real time.
 
Upvote 0
Top