Game Development Community

Script Memory Leak?

by Bin LU · in iTorque 2D · 06/29/2009 (9:39 am) · 10 replies

My game write in pure Torque scripts.
And I don't think I did some unsafe operation cause memory leak.
But when I test the game by Instruments,I see the memory use by the game increasing for a long time,more time played,more memory used,and the game crashed.

Why? Any tips for me to free the memory in Torque Scripts?

My game will create up to 30 balls,and these ball will scale to a bigger ball then destoried,I use the safeDelete() method to delete the ball object when it should be removed from screen,Am I right?

Other thing I need to do to free the memory when I load next level?
What I need to do when I load next level?any method to unload current Level?

Plz help me,I'm worried about performance of my game,the frame drops very terriable. And the game will crashed when the memory goes to about 60 MB.


#1
06/29/2009 (1:11 pm)
There is no way to free memory in torque script that leaks as the error happens within the VM, not within the script likely
#2
06/29/2009 (6:28 pm)
@Marc error? what's the error make VM memory leaks.How can I do to make memory not increase so fast?
#3
06/29/2009 (6:29 pm)
No idea what the actual error is

I would recommend that you give the Apple documentation and the XCode Instruments for Leaks and Object allocation and indepth visit
#4
06/30/2009 (6:41 pm)
My concern is iTGB isn't optimized for iPhone.It just use the render mechanism for Desktop on iPhone.
#5
06/30/2009 (6:45 pm)
thats more or less true

there are a few things that are optimized (or were at least attempted to be adressed like the scripting) but there are various things that are pretty unoptimized or anti-optimized.

I'm currently altering the engine for my projects needs to overcome that.
At the time the regular shooter components already runs at 20-25FPS on an itouch 1st gen, where it commonly is happy to be at 15 FPS actually
#6
06/30/2009 (9:37 pm)
@Bin LU:

I've had the same problem. I tried to do a very script-heavy, 100% script game and I had a leak that caused the game to crash in 20 minutes. After a decent amount of time trying to fix it, I simply gave up. I've now rewritten the game in C++, with a small amount of script. It runs great.

iTGB, imo, isn't as easy of an engine solution as TGB is for the PC. But then the platform isn't as "easy" either. So bumping up against this kind of thing, while annoying, is part of the platform's reality I think.
#7
06/30/2009 (10:34 pm)
That it runs that bad has little to do with the easy and not easy part.
There are just a significant amount of common base behaviours missing in iTGB at the time (batching is a base requirement for example, but isn't present. Not even on particle and tile layer where it is basically free)

iTGB is a solid base to build a real iPhone technology with, it just has to be done.
Too many things that "work" on the pc because the cpu and graphic card drivers compensate for the unoptimized handling in TGB are still done the very same wrong (wrong as in unoptimized) way on the iphone

Additionally iTGB doesn't attempt to benefit from the special behaviours of the gpu (it works pretty different than desktop ones, much more efficient with powerfull early drop mechanisms etc), nor does iTGB use the VFP which would accelerate the transformations and other "calculation chains" drastically.
#8
07/02/2009 (7:21 am)
@Chris, just wondering how long did it take you to convert your game to C++ and how much of an improvement did you see? I am worried I may have a leak also my game is in 100% script right now, but when I try to use the leak monitor tool in xcode when my game gets to the main menu it doesnt respond to anything I do so I cant even get in to the actual game to see. Either way if C++ is enough of a difference it may be worth my time to at least try.

@Marc, what kinds of things did you alter to see that much of an fps boost? Would you be willing to do a writeup at all of the changes you made? I have been wanting to optimize the engine for myself as well but its quite the daunting task with the shear amount of stuff in it.
#9
07/02/2009 (9:09 am)
The changes I did are pretty much project specific with object pooling for example. That holds true for most modifications I think.

And yes its definitely a daunting task and I would love to spend my time on important things but it is as it is.
#10
07/02/2009 (9:15 am)
@Zeinad: Hard to give an exact timeline. I redid the entire game logic in C++ and added in script hooks to get it going. I also added in some unique features, like on-demand datablock creation, etc, etc... Plus new art, new music, new sounds... So it was almost like doing a new game from scratch in this case. I'd say it doubled the dev time... half to write in script, half to rewrite in C++.

With that said, it's much faster. I'd approximate a 4X speedup. Plus, the script version would slow down as the game played on and more pieces were on the board. The C++ version never slows. Game is here for context.