Page 1 of 1

memory leak

Posted: Mon Jun 15, 2009 9:19 pm
by zuzuf
It seems there is a big memory leak in the code :(

I played nearly 2 hours, and it ended using 3.1GB of RAM :shock: , it didn't even release this memory after game ended :cry: so it is definitely a memory leak, and a big one :evil:

Re: memory leak

Posted: Mon Jun 15, 2009 9:22 pm
by Griswoldz
The code needs debugging then. I would suggest Cheat engine trainer maker, as it can actually show WHAT writes WHERE. Perhaps it will help :P.

Re: memory leak

Posted: Mon Jun 15, 2009 11:33 pm
by zuzuf
There are lots of memory allocation/deallocation during a single frame/tick, it'll be a real nightmare to find the leak analyzing the code and what it's doing. I think a good way to trace the leak is to find when we introduced it by testing previous revisions, just spawn 1000 vs 1000 units, if there is the leak it'll be obvious. Hopefully search time is logarithmic :P. I'll do that tomorrow :D

Re: memory leak

Posted: Mon Jun 15, 2009 11:48 pm
by Griswoldz
Alright :D. I'll be ready to test the new upcoming version by focusing on RAM-hunger of it. Rawr.

Re: memory leak

Posted: Tue Jun 16, 2009 5:16 am
by Balthazar
In this case I`ll try to do the same test on a8,a7 and a6 :P

Re: memory leak

Posted: Tue Jun 16, 2009 6:41 am
by xpoy
I'll help in this in tonight.
:p Best in debug

Re: memory leak

Posted: Tue Jun 16, 2009 10:39 am
by milipili
"Intruments" on OS X already told where the leak is. It will be fixed as soon as possible (unless zuzuf fixes it before ^^)

Re: memory leak

Posted: Tue Jun 16, 2009 11:07 am
by zuzuf
nice, where is it ? :mrgreen:

Re: memory leak

Posted: Tue Jun 16, 2009 12:00 pm
by xpoy
The memory wasn't in excess of the accident when spawn lots of units. I spawn 10000 units for test. :P
Interesting, spwan 0 0 10000 in a land and sea map faster than spawn 0 0 1000 units in a land map.


This is crash when close that game table:
07D9FE9C 7C8023ED ntdll.ZwDelayExecution kernel32.7C8023E7 07D9FEF0
07D9FEA0 00000000 Arg1 = 00000000
07D9FEA4 07D9FEC8 Arg2 = 07D9FEC8
07D9FEF4 7C802451 ? kernel32.SleepEx kernel32.7C80244C 07D9FEF0
07D9FEF8 00000064 Timeout = 100. ms
07D9FEFC 00000000 Alertable = FALSE
07D9FF04 6813EA21 ? <jmp.&KERNEL32.Sleep> SDL.6813EA1C 07D9FF00
07D9FF08 00000064 Timeout = 100. ms
07D9FF14 004DDD3C <jmp.&SDL.SDL_Delay> ta3d.004DDD37 07D9FF10
07D9FF24 00658D8B 包含ta3d.004DDD3C ta3d.00658D88 07D9FF20
07D9FF44 6810A2EC 包含ta3d.00658D8B SDL.6810A2EA 07D9FF40
07D9FF64 6813E4C9 SDL.6810A2B0 SDL.6813E4C4 07D9FF60
07D9FF84 77C0A3B0 包含SDL.6813E4C9 msvcrt.77C0A3AD 07D9FF80


Thus that was a menu show problem. :P

It crash when close a old thread and sdl_delay, like a wrong argc or a pointer wrong struct

Re: memory leak

Posted: Tue Jun 16, 2009 2:08 pm
by zuzuf
spawning 10000 units is unwise ... unless you set up the maximum unit per player count to something like 10000 instead of 2000 (which is already too much if AI can get so much units)

Re: memory leak

Posted: Tue Jun 16, 2009 2:41 pm
by Balthazar
Yeah, I`ve noticed the same bug.... on 0.6.0.a8, a7 and a6. But when i quit TA3D the used memory frees, so no memory losing detected.

Re: memory leak

Posted: Tue Jun 16, 2009 2:46 pm
by xpoy
I used ahpla 8, and play a 1000 vs 1000 units.
This is test PC:
AMD athlon 64 3000+
1.99 GHz, 1.00 GB mem
Gfx5200


And OMG, I love this. It was normal FPS, and all work normal ingame! I didn't notice that lots of memory leak, but be 270 MB when alt tab to game, 160 MB when alt tab out. And first time alt tab made game freez in 10 seconds. First time spawn was very slow, but next be faster.
When I lose, yes , AI kick my control nothings ass, the memory be 32MB, just crash when quit table.
And yes, I should try defeat 1000 KROGs at now, haha

Re: memory leak

Posted: Tue Jun 16, 2009 3:42 pm
by zuzuf
when you exit TA3D, the OS frees the memory it allocated. This is normal behaviour since a program allocates "virtual memory" that is mapped onto the system RAM when needed (a program can allocate more memory than you have RAM as long as the CPU can address it, so 3.2GB max on 32bits CPUs and much more with a 64bits one :P, it'll only swap to the disk)

Re: memory leak

Posted: Tue Jun 16, 2009 3:54 pm
by Balthazar
it didn't even release this memory after game ended
- sorry, my bad. Wrong translated :P

Re: memory leak

Posted: Wed Jun 17, 2009 6:23 am
by xpoy
This is a platform or system proble, I didn't meet it even 1 hour play.
But it was really cost some time for cache that first time switch in Strategic perspective and normal perspective.
But all other work well.
And there are 90MB used when quit game, I alt tab out then in the game, mem be normal 20MB.

The mouse shouldn't be slow when game fell tired, just made mouse and keyboard work normal then a big part finshed

In last, I got one crash, oh it really cost long time.
And a intereting thing, in the last 5 mins, I found the metal and energy text be fuzzy

Re: memory leak

Posted: Wed Jun 17, 2009 8:08 am
by zuzuf
I run TA3D with Valgrind which tolds me there was a total memory leak of 48MB for a very short game (a few minutes running at 3fps - yes this is because of Valgrind) with 100 units spawned on the map. So there is definitely a big memory leak.

Re: memory leak

Posted: Wed Jun 17, 2009 3:58 pm
by Balthazar
milipili wrote:"Intruments" on OS X already told where the leak is. It will be fixed as soon as possible (unless zuzuf fixes it before ^^)
Tell us where is it :P

Re: memory leak

Posted: Wed Jun 17, 2009 5:00 pm
by xpoy
There are Linux used in malloc manage, but Win32 just used in malloc count, or some other nearly shape wrong.
I just guessing, need milipili told us....

Re: memory leak

Posted: Wed Jun 17, 2009 5:22 pm
by zuzuf
Those ugly leaks seem to be gone :P

Re: memory leak

Posted: Wed Jun 17, 2009 6:05 pm
by Balthazar
Whould you build a new test binaries to be sure ? :P

P.S. Maybe end sission crash have been connected to this.

Re: memory leak

Posted: Wed Jun 17, 2009 6:21 pm
by zuzuf
I doubt it was because a memory leak doesn't produce memory corruption, this is something else.

Re: memory leak

Posted: Thu Jun 18, 2009 8:45 am
by xpoy
调用堆栈: 线程 00000858, 条目 2
地址=0DC8F094
堆栈=7C81AD0A
函数过程 / 参数=ntdll.CsrClientCallServer
调用来自=kernel32.7C81AD04
结构=0DC8F090

well, there are a problem in win32 input code.
It crash when I spawn 1000vs 1000 unit and zoom out lot times as soon as screen start refresh

log file:
stdout.rar
(17.67 KiB) Downloaded 677 times

Re: memory leak

Posted: Thu Jun 18, 2009 4:08 pm
by zuzuf
if you remove *.lua files from scripts/ and *.3dm from objects3d/ does it still crash ?
Does it still crash with only totala1.hpi/totala2.hpi, with and without TA:CC files ?

Re: memory leak

Posted: Thu Jun 18, 2009 5:26 pm
by xpoy
It was a lua problem, I only test 2 times, look like delete lua file fix this problem, I spawn then ctrl_z/ ctrl_z/...... and zoom out zoom in, game keep going without any wrong. /:^]

But found new thing:
My all units die by somethings, But I think there no things could kill 300 units around all map in a second, log file

Re: memory leak

Posted: Thu Jun 18, 2009 7:05 pm
by zuzuf
maybe it's a chained explosion of commanders :P, or AI's secret super weapon :mrgreen:

But I know a 3rd party unit capable of killing thousands of units at once : the Armageddon, it's a kind of atomic bomb, except it's radius is much bigger :mrgreen: (if you use it on small maps, no one wins ...)

Also a ctrl+D can suicide all your units if you accidentally press it ...

Re: memory leak

Posted: Thu Jun 18, 2009 7:57 pm
by xpoy
Yes, it can be a wrong ctrl_s,really nearly
But I found log didn't help in this /:^[
May log user input cost too many CPU, but it was need in ahpha version, maybe, :)