Community
SCI Programming => SCI Syntax Help => Topic started by: Doan Sephim on May 12, 2007, 10:42:16 PM
-
I actually know exactly what is "eating" my heap...and when I say "eating" I mean that the game is losing heap space every game cycle and when I switch rooms the heap does not reset as it should. Some heap is simply MIA!! Restarting the game restores the heap, but that would probably be expected.
Here is what I am doing. I have a region that I am accessing. In the region's doit method I have this:
(= myEvent Event:new(evNULL))The above code is what is "eating" the heap.
I am then using the "myEvent" x and y values to have certain actions happen when the cursor is simply in a certain area, so there are two probable ways to solve my problem...either determine why the code is leaking heap or use a different way to achieve the same goal...either way I would be happy with ;)
However the myEvent code (which I found in Cloudee1's aquarius game) for some reason munches away on heap space. I assume it wasn't a problem in Cloudee1's game as I never had the heap space run out...might it have something to do with my using it in a region??
-
Well, you're creating a new Event object on the heap every game cycle and never deleting it.
So you need to delete it right after you're done using it:
(send myEvent:dispose())
-
Hey thanks! That works perfect! This kinda stuff always happens when I don't REALLY know how something works and I just copy and paste!
Thanks for clarifying what exactly I was doing! I feel stupid when I post questions and there is only ONE small snippet of code that solves all the problems...lol.
BTW...thanks a ton Troflip for those more advanced tutorials! They have served me quite well lately! I never EVER would've figured out quite how to use regions without those tutorials.
-
Yeah, you hardly ever need to think about memory management if you just do "normal" stuff with the template game. For example if you do the "View:new()addToPic()" thing, you don't need to do anything special, because the View adds itself to a global list of objects that automatically gets disposed of when you change rooms.
But not so with most other things that you :new()
Glad the tutorials help :)
-
There's also another thing you could do. Instantiate an Event object like
(instance myEvent of Event
(properties))
Then in your main code, say:
GetEvent(evNULL myEvent)
This way, you don't need to allocate/deallocate memory all the time.