Monkey's GC, what's going on?

Monkey Forums/Monkey Programming/Monkey's GC, what's going on?

AdamRedwoods(Posted 2012) [#1]
I'm attempting to dissect Monkey's GC to help put together wxWidgets.

My understanding is the GC will mark everything to be kept each sweep. Right now I think I default continuous GC (CFG_CPP_GC_TRIGGER 0).

So here's my example:


extern code
gc_testing.cpp


You'll see I'm using extern objects, trying to get them to cooperate with the GC. I've overloaded the GC calls to tell me whats going on.

So far, the above code calls Sunshine::mark() twice-- but that's all.
Shouldn't the GC be calling mark() every time gc_collect() is called (which is after every OnUpdate() )??

Now, if you add in the List<Int> loop, suddenly we are calling Sunshine::mark() every gc_collect as expected.



Question 2, so if I change this:
	Method OnUpdate()

		'For Local b:Int=Eachin list
			'do
		'Next
		
		If KeyDown(KEY_SPACE)
			sun = Null
		Endif
		
		If sun Then sun.Pop()
		Print "---"
	End


Then when I press space, sun is gone... but when is it gc deleted? When i add the loop iterator, it is gc deleted there.

Why? Is it because I'm not triggering a gc_assign() which does the actual memory freeing? Even if I add this routine in, or create a new instance of some other class, it does not delete my Sunshine Object. Only if I use the eachin iterator.

I think I am missing something, but I'm not sure what it is.
Thanks!


marksibly(Posted 2012) [#2]
Hi,

Bytes allocated since last sweep must be >TRIGGER for GC to occur, so you must allocate at least 1 byte, which the For Eachin loop does since it allocates the iterator.


AdamRedwoods(Posted 2012) [#3]
Ok, that actually pointed me in the right direction, thanks.

So, what about if I add "n=New WhateverClass()" every frame? Doing this does not trigger. I realize it will be the same size allocated every time, but aren't we allocating new data, THEN releasing the old?

EDIT:
i guess this is what i'm stuck on, since I cannot get wxBitmap to release the old data, even when creating a new instance. it doesn't trigger.


AdamRedwoods(Posted 2012) [#4]
calling this before gc_collect seems to work:
void gc_force() {
	gc_object* force = new gc_object();
}


But I still have a memory leak somewhere, but probably somewhere else.


AdamRedwoods(Posted 2012) [#5]
I've noticed that the GC does not work with separate processes.
In wxWidgets, when a file dialog request window pops up, I have the GC running on a one second interval in a separate process, which then dtors the file dialog object.

I'm thinking this isn't the best way to do the GC, since it seems it will destroy any locally defined objects, while a file dialog is up. There also doesn't seem to be a way to destroy objects based only on scope.

Not sure how to handle this since wxWidgets is event based, so calling GC from MainLoop() would have the same effect. Ideas?

EDIT:
well, i discovered that wxIdle on the main app window isn't called when a modal window has control, so that takes care of most of that. I just wonder about other processes/non-modal and if i should allow them.