[1.3b60] Memory Leak

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice, MapTool BugReport Manager

Post Reply
dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

[1.3b60] Memory Leak

Post by dorpond »

I think I may have found a memory leak. Perhaps some of you can try this at home.

I have a campaign file with around 12 maps in it. If I load up the campaign and switch to the first map, I am using 88/386 memory. If I then switch between 4-5 maps and return to the first map, i may be using 180/386. If I switch through more maps and return to the first, I will be using 240/400. The numbers keep going up. Eventually, I won't be able to save because I am out of RAM (512 setting in MT).

I notified Trevor and sent him my campaign. I am bringing this up here so you guys can see if you are experiencing the same behavior.
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: [1.3b60] Memory Leak

Post by Phergus »

I can't make it happen here. I tried first with an existing campaign that had maps mostly made with tiles and a fair amount of texture drawing. It just never went up hardly at all once the biggest map had been loaded once.

Then I created a new campaign with 14 different maps made of single image maps of various sizes from 1k x 2k to 3k x 4k. The memory went up to 383M at one point but if I double-clicked on the memory counter the garbage collection took it right back down again. Saved the campaign and then started afresh with a reload of the campaign. Cycling between the maps saw the max memory go just over 400M but it just bounced up and down between 200M and 400M in usage.

Some kind of OnLoad macro on the maps that keeps eating up memory? Maybe adding the same info over and over to one global array or list?

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: [1.3b60] Memory Leak

Post by dorpond »

Thanks for the testing Phergus.
Feel free to test my campaign file:
http://dorpond.rptools.net/Temp/DiabloB60.cmpgn
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: [1.3b60] Memory Leak

Post by Phergus »

Definitely something going on with your campaign. Cycling through the maps pushed up the constant memory usage to 420M with a max of just under 800M.

Won't swear to it but the amount of increased memory used that wouldn't come back seemed to correlate with how many tokens were on a given map.

I'll have to play with it some in the IDE to see where the memory is going.

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: [1.3b60] Memory Leak

Post by Phergus »

Looking at it in a memory profiler wasn't a huge help. As it basically just says there are a whole lot of integer arrays being allocated but never released. Was hoping it would have pointed to a particular class.

Not liking the numbers on any of the top suspects.
MemoryUsage.png
MemoryUsage.png (52.95 KiB) Viewed 6809 times

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: [1.3b60] Memory Leak

Post by Azhrei »

Phergus wrote:Looking at it in a memory profiler wasn't a huge help. As it basically just says there are a whole lot of integer arrays being allocated but never released. Was hoping it would have pointed to a particular class.
The int arrays will be all graphics images. So it does (sort of) point to a potential problem with image caching.

I don't think MT uses weak references for graphics images, but I seem to recall thinking about it when I was bouncing around inside the image handling code while creating my (not yet finished) super-duper export function. That code is a bit of a mess (at least to my level of understanding!) but I don't recall seeing any obvious memory leaks there. And I had to get into it fairly deep at the time.

I wonder if it could be related to the fact that images are loaded in a separate thread? So you switch maps and a bunch of image requests get dumped into a queue. Some are resolved immediately (never really flushed from RAM) and the rest cause file I/O to the original asset location. But the asset somehow has a new GUID assigned to it and it gets a different slot in memory. So there are now two references to the same image.

Obviously shouldn't be possible, but if there were a bug...

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: [1.3b60] Memory Leak

Post by Phergus »

If it was just image caching I would think I could have reproduced it with one of my campaigns. My working campaigns are very similar to Dorponds. Mixes of static map images, texture drawings, lots of objects. VBL complexity is about the same.

But given the amount of memory being held it almost has to be images. My guess at the moment is that a reference to a drawing buffer for each map is being kept even when that map is not displayed. Or maybe even all of the images for a given map are being kept in memory.

With Dorponds campaign once it reaches that 400M or so point it never goes up any higher for me. So MT has cached everything it is going to at that point.

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Re: [1.3b60] Memory Leak

Post by trevor »

K, found and fixed this last night.

MT used to flush all images from the cache each time you switched maps.

Somehow, somewhere, (someone?) removed that code, so images were never getting flushed.

In dorpond's campaign, each of the many maps had tons of large and unique images, which made the problem show up. If he had shown all maps and the switched around, the memory would have stayed constant because all images were stuffed in memory.

I've fixed it up so that when you switch maps it flushes all images that are not in the new map.
Dreaming of a 1.3 release

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Re: [1.3b60] Memory Leak

Post by trevor »

this is fixed for 1.3b62
Dreaming of a 1.3 release

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: [1.3b60] Memory Leak

Post by Azhrei »

Excellent! Good work. :)

Post Reply

Return to “Resolved”