Memory Leak

dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Memory Leak

Post by dc37 »

While the garbage collector does appear to do its job whenever the window is in focus, the program still seems to like to very quickly climb up to about 2GB of memory usage when sitting idle. (picture attached). If I put the window back into focus, the GC appears to do its job pretty readily. The climb-rate is pretty high - the memory usage hits 2GB in a matter of about a minute. Does anyone know what the cause of this might be? I'm working on getting the development environment and Git material setup so that I can perhaps contribute to making the software better.

Computer used for the LitePlacer is a fairly weathered machine, nothing fancy, but also not unreasonably slow:
Win7 64-bit
Intel Core 2 Duo E6580 3.00GHz
4GB RAM (can easily add more if needed, but haven't had the need yet)
Attachments
Picture of memory leak
Picture of memory leak
MemLeak.png (5.88 KiB) Viewed 6268 times
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

Here is another screenshot; I reproduced the error whilst debugging using Visual Studio 2013
Attachments
MemLeak2.png
MemLeak2.png (98.52 KiB) Viewed 6257 times
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

I tried to reproduce this but failed. Just checking, are you using the latest (this week) update? The changes might have fixed this already (or not). If yes, obviously I need to look much deeper.
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

Yes, I am using the 1/13/2016 update.

EDIT: I just saw your commit on GitHub (https://github.com/jkuusama/LitePlacer- ... 6d8c2c97af); tried merging in the changes. The memory used by the application is much more stable now, though it seems like the cameras are now not receiving frames...
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

Hmph. For development, it is good to have a system that reliably fails. It is not so good if all of those systems are at customers. I didn't have a memory issue to begin with, but I did see activity on the garbage collector at some situations. Today's version is stable in that regard for me too, but I do get frames. Obviously, I overdid it; I should not dispose all frames, some should go to display, too.

But I think I'm on a right track. Apparently, this is Windows/NET version specific (as I don't have these issues). If the image boxes or some other part of the chain does not dispose old video frames when getting a new one, memory would fill up fast. You didn't show units in your graph, but it is maybe about 1GB/minute, which is suspiciously close to 480*640 pixels, 1 byte per pixel ( which is 0.3MB/frame) at 50 frames/s (which is 3000 frames / minute) = 0.9GB.

Back to the lab...
User avatar
Mark Harris
Posts: 38
Joined: Sat Nov 14, 2015 12:34 am
Location: Calgary, AB

Re: Memory Leak

Post by Mark Harris »

Buy something like ReSharper, CodeRush or JustCode - it will tell you all the places you havent correctly disposed of an IDisposable and can add using () { .. } statements.

Using Telerik's JustTrace will tell you exactly where you're building up objects, and allow you to optimise your code a lot too ;)
mawa
Posts: 139
Joined: Wed Jun 10, 2015 1:23 pm
Location: Near Hamburg, Germany

Re: Memory Leak

Post by mawa »

When I started my merged Liteplacer Version I found several missing disposals in the graphic routines (bitmaps, graphics, brushes, pens) from Juha and reza.

I am using CodeRush btw. and due to the fact that I deal a lot with graphics in my commercial applications you get a sense for that creeping out of memory bomb.

I already pointed out that fact last July, but it seemed to have been ignored :cry:

http://liteplacer.com/phpBB/viewtopic.p ... +leak#p525

rezas "garbage collector cleans everything up" is IMHO wrong because these objects are unmanaged memory allocations and are not under the GC surveillance.
best regards
Manfred
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

No, it was not ignored, this is more involved. I'm not sure what exactly is happening (would I know, I'd fix it), but in some cases and some systems*, the disposing doesn't work. The programmer's fault, of course, but if I dispose used video frames late or rely the image box to do it (current release) they might get piled up when the image is not displayed (minimized, background). If I dispose early (currently the topmost on GitHub), some systems don't display the image in the first place.

*: My garbage collector is better than dc37's. The only hint of a potential problem I see is some more activity on memory usage at some situations. My version of.NET or Windows itself is also better than some people who have tried the current GitHub version. I see video when they don't.

I'll keep working on this and obviously, I also need to get some better tools.
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

If it's an outdated .NET version, then maybe an update will fix it? I'll see what happens when I do that.

Update: I made sure that the .NET framework 4.5.2 was installed and that Win7 was reasonably up to date with updates (last updated ~Dec 10)
Unfortunately I still have the same problem.
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

More information that may help with debug: This error seems to be the worst when I am in the "basic setup" tab. With other tabs, it seems like the GC is doing its job properly.
Post Reply