Tracking down a memory leak

joneden

Active Member
Licensed User
Hi All,

I'm trying to find the source of a memory leak somewhere in my app.

I haven't had any success in getting a current memory size value - I can get the total memory but not what is currently available.

Does anyone have any advice for tracking down memory leaks, or possibly knows of some apps etc that would help?

Best Regards

Jon
 

Informatix

Expert
Licensed User
Hi All,

I'm trying to find the source of a memory leak somewhere in my app.

I haven't had any success in getting a current memory size value - I can get the total memory but not what is currently available.

Does anyone have any advice for tracking down memory leaks, or possibly knows of some apps etc that would help?

Best Regards

Jon

In C:\Android\android-sdk\tools, you'll find Monitor.bat.
If your application does not appear in the list under your device, add this line to your manifest:
SetApplicationAttribute(android:debuggable, "true")
Then click on the first green icon in the icon bar (update heap) and select the heap tab on the right. You can see now all memory allocations in pseudo real-time.
 
Upvote 0

joneden

Active Member
Licensed User
Hi Erel,

No this is on a unit that runs for days before hitting any issue and it didn't seem to have any error as such in the log. When going into the app manager I saw that the avail memory was down at about 8Mb.

I'm going to try a few things using the pointer that Informatix gave me, hopefully then I can isolate any areas of the software that could be causing this.

Regards

Jon
 
Upvote 0

joneden

Active Member
Licensed User
Hi Erel,

It was weird that it didn't throw an error. Sadly one of the issues that could cause it requires manual intervention and can't be automated - barcode scanning.

Regards,

Jon
 
Upvote 0

aalekizoglou

Member
Licensed User
Is this causing memory leaking

In the code above, do I need to manually destroy objects to prevent memory leaking, or the garbage collector will take care of them?

B4X:
'Class module
Sub Class_Globals
   Type typeDataSet(Rows As List)
   Private Dataset As typeDataSet
End Sub

'Initialize
Public Sub Initialize
   Dataset.FieldsDescr.Initialize
   Dataset.Rows.Initialize

   SomeFunction   
        SomeFunction   'Does this call generates memory leak??

End Sub

Private Sub SomeFunction
   Dim i As Long
   
   'Should I iterate through previous rows and destroy??
   Dataset.Rows.Initialize
      
   For i = 0 To 9
      Dim row(2) As Object
      row(0) = i
      row(1) = 'test' * i
      Dataset.Rows.Add(row)
   Next
End Sub
 
Last edited:
Upvote 0
Top