Can anyone spot the memory leak in this code?

Mickster

Active Member
Licensed User
Longtime User
I must have tried about 100 different variations to get this code to work properly and I think I'm going insane.

B4X:
Sub btnAxisInterface_Click
   
   Dim imgDocImg As ImageView
   imgDocImg.Initialize("imgDocImg")
   Activity.AddView(imgDocImg, 0, 0, Activity.Width, Activity.Height)
   bmpDocImg.Initialize(File.DirAssets, "Axis_Interface.png")
   imgDocImg.Bitmap = bmpDocImg

End Sub
Sub imgDocImg_Click
   
   Dim test As ImageView
   test = Activity.GetView(Activity.NumberOfViews-1)
   test.RemoveView
   test = Null
   DoEvents
   
   Dim recycle As Reflector
   recycle.Target = bmpDocImg
   recycle.RunMethod("recycle")
   bmpDocImg = Null
   
End Sub

I've tried many variations with and without the recycle method but I can't prevent the leak. Anyone see where I've gone wrong?
 

Mickster

Active Member
Licensed User
Longtime User
The images are fairly large, but the end result would be loading several (9 or 10) in quick succession. I'm just trying to get the code to work with this one image for now.

** 9 to 10 images is too much to store simultaneously.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
The images are already at the right resolution. In some cases, I'm going to need images that are higher than the device resolution in order to read fine text.
For test purposes, I built a small app that cycles through all the images I intend to use and it did so without any leak. I didn't need to use the recycle method, GC was able to keep up by itself. My main project has a lot more going on, though. Do you think I could be asking too much of the device/OS?
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
The images are schematics. They display a lot of information and one or two of the images need a high resolution in order to make all the info legible. They're called with a button, they fill the screen and when the user has finished looking at them, they close. I only need one in memory at once and then they should be removed.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
It seems to spark some GC activity in the log but unfortunately it isn't helping the leak. I'll bite the bullet and see how much damage loading them on boot will do.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Well, after loading half the images in on boot I have a head size of near 200mb :icon_clap:

In the end I decided to load the schematics into a web view. I get scrolling and pinch to zoom functionality and it appears as though the memory is handled fine.

Thanks for trying to help, appreciate it!
 
Upvote 0
Top