Garbage Collector not working?

Monkey Targets Forums/iOS/Garbage Collector not working?

mouser(Posted 2013) [#1]
Hi,

this is my litte app:

Strict

Import mojo
Import monkey

Class Game Extends App

    Field img:Image

    Method OnCreate:Int()
	SetUpdateRate(60)
	Return 0
    End

    Method OnUpdate:Int()

        If (TouchHit(0) > 0) Then

	    If (Image(img)) Then
		Print "delete picture"
		img = Null
	    Else
		Print "load picture"
		img = LoadImage("test.jpg")
	    EndIf

	EndIf
		
	Return 0
    End	
		
    Method OnRender:Int()
	Cls()
	If(Image(img)) Then DrawImage(img, 0, 0)
	Return 0
    End
End

Function Main:Int()
    New Game()
    Return 0
End


I run this app on my iPad 3 and tab around 50 times on it.
Now the app uses permanent 500 MB.

It's much better with img.Discard() but shouldn't "img = NUll" free the memory also?


tested with XCode 5 and iOS 7


ElectricBoogaloo(Posted 2013) [#2]
Out of curiosity, what happens if you try loading different images (eg LoadImage("image"+Int(Rnd(0,9))+".jpg")

There's a lot of things we need to figure out with XCode5 and iOS7, and it's good to experiment with these things, and learn what does and doesn't work.


ziggy(Posted 2013) [#3]
Nulling anything does not mean that it is automatically being collected. It just means that is ready for collection.
When you want a given resource (such as an image) to be freed, you have to discard it.
If the memory pressure is high, then the GC will eventually decide to collect the nulled images. Until this is done, images are kept on memory and on VRAM. So, all in all, I would suggest to always Discard images when you want to unload them and free resources.


mouser(Posted 2013) [#4]
I tested a little bit around and img.Discard() works fine with normal images but seems to be ignored by images with frames.

Field img1:Image
Field img2:Image

img1 = LoadImage("test1.jpg")
img2 = LoadImage("test2.jpg", 100, 100, 10)

img1.Discard() ' -> works fine
img2.Discard() ' -> no effect!


seemingly there is a kind of image atlas and I can't discard it.


maverick69(Posted 2013) [#5]
I can confirm that Image.Discard() does nothing on ios when loaded up an image with multiple frames. (MonkeyV74A, iOS7, xCode5)


Raph(Posted 2013) [#6]
Seems like that should maybe go in the Bug Reports forum?


maverick69(Posted 2013) [#7]
Can someone move that to the bug forum? I think that is a serious issue that should be addressed.


rIKmAN(Posted 2013) [#8]
I have reposted in the bugs forum, hopefully someone will eventually move this thread in there.

Link