4096 channel limit - unable to clear channels

BlitzMax Forums/BlitzMax Programming/4096 channel limit - unable to clear channels

Grey Alien(Posted 2007) [#1]
Please can you test this code and see if you can see where I've gone wrong, thanks!

Basically at loop iteration 4096 when 4095 channels have been allocated and supposedly freed with StopChannel() it bombs with "attempt to access field or method of null object) on the StopChannel line. This is because the channel is null because AllocChannel starts returning null after channel 4096.

The limit is not the issue here, that's fine, the issue is why aren't they freeing up?

I'm running 1.24. Syncmoded a few months back (after Mark's new DX7 rewrite) but not since.

For Local i=1 To 5000
	Local c:TChannel = AllocChannel()
	StopChannel(c)
	c=null
	GCCollect 'safety
	Print i
Next


This has probably meant that my games bombs if you play them long enough. :-(


ziggy(Posted 2007) [#2]
It sounds like a bug to me...


Grey Alien(Posted 2007) [#3]
nothing wrong with the memory i.e. it appears to be freed:

GCCollect 'safety
For Local i=1 To 5000
	GCCollect() 'safety
	Local before = GCMemAlloced()
	Local c:TChannel = AllocChannel()
	GCCollect() 'safety
	Local after = GCMemAlloced()
	StopChannel(c)
	c=Null
	GCCollect() 'safety
	Local freed = GCMemAlloced()
	Print i + " before:"+before+" after:"+after+" freed:"+freed
Next



tonyg(Posted 2007) [#4]
It works OK for me and I'm fully up-to-date with syncmods.


Tachyon(Posted 2007) [#5]
Works for me too...fully sync'd.

Have you sync'd up with any of the sound changes that Mark and Skid did a few months back? I know there was a 4096 channel bug then that was fixed.


tonyg(Posted 2007) [#6]
this ?


Grey Alien(Posted 2007) [#7]
OK thanks. I'll sync mods and see what happens.


Grey Alien(Posted 2007) [#8]
Fine now. thanks. So the moral of the story is always syncmods before reporting possible bugs.


Dreamora(Posted 2007) [#9]
there is another problem with this code.

Local do not need to be freed within the scope or are at least not guaranteed to do so ...

so this test, even before the sync, does not needfully show the real state unless you put the local within another scope which it has to leave.


Grey Alien(Posted 2007) [#10]
so even after making it null and calling GCCollect?


Dreamora(Posted 2007) [#11]
At least from what stated.

Local are local to a scope and until that scope is left, the GC does not directly handle them.

Thats why you should never use locals on application level as they are not fully GC bound and do not show up in the GCMemAlloced for example.


tonyg(Posted 2007) [#12]
Local are local to a scope and until that scope is left, the GC does not directly handle them.

Sure you must be right but where do you get that information from?
Using this you can see objects and memory being released each gccollect
bbGCSetDebug(1)

For Local i=1 To 5000
	Local c:TChannel = AllocChannel()
	StopChannel(c)
	c=Null
'	GCCollect 'safety
	Print GCMemAlloced()
	Print i
Next
Extern
	Function bbGCSetDebug(mode:Int)
EndExtern



Grey Alien(Posted 2007) [#13]
Thats why you should never use locals on application level as they are not fully GC bound and do not show up in the GCMemAlloced for example.
Ah, I'm OK as I use globals there.