GCSuspend()
BlitzMax Forums/BlitzMax Programming/GCSuspend()
| ||
How does GCSuspend() work? Will objects created between a call to GCSuspend() and GCResume() create memory leaks, or will they get cleaned up some time after GCResume() is called? |
| ||
This seems to suggest GCSuspend() and GCResume() don't cause memory leaks. Let it run for a few seconds, then press Space. Strict Graphics 800,600 GCSuspend() While Not KeyDown(key_escape) Cls DrawText GCMemAlloced(),10,10 Flip If KeyHit(key_space) GCResume() EndIf Wend End |
| ||
You're right. However, today I spent a large amount of time tracking down a bug that finally led back to a large number of GCSuspend() and GCResume() calls. I could not produce the error on my single-core machine, but one user's quad core did produce an error. I finally resolved this by eliminating all those GCSuspend/Resume calls. It is a little worrying to me that only his quad core was able to produce an error, and my single core ran fine. I wasn't attempting any multithreading stuff. Strict Graphics 800,600 Type TFoo Field data:Int[1000] EndType Local foo:TFoo GCSuspend() While Not KeyDown(key_escape) foo=New TFoo Cls DrawText GCMemAlloced(),10,10 Flip If KeyHit(key_space) GCResume() EndIf Wend End |
| ||
Do you have mismatched GCSuspends/GCResumes? Run your example above and press space twice. Massive memory leak. Running on a dual core cpu here, if it matters. |
| ||
I am pretty sure they were not mismatched. However, we are talking thousands of calls per second, so it was probably a poor design on my part anyways. |
| ||
Yes you do, the problem you have there is when you press space its read for as long as you hold it down and all the time GCResume() is called.Strict Graphics 800,600 Type TFoo Field data:Int[1000] EndType Local foo:TFoo GCSuspend() Global GCOff:Int = True While Not KeyDown(key_escape) foo=New TFoo Cls DrawText GCMemAlloced(),10,10 Flip If KeyHit(key_space) If GCOff=True GCResume() GCOff = False EndIf EndIf Wend End Should fix this. |
| ||
Yes you do, the problem you have there is when you press space its read for as long as you hold it down and all the time GCResume() is called. No, I used KeyHit, not KeyDown.Using KeyHit, if I press Space and hold it down for half an hour, it'll still only register one hit. |