Memory Leak

JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

dc37 wrote: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.
Also when the app is minimized; at least I see more GC collector activity there, although my systems don't leak. What I assume is going on that the image box code that throws away the old frames (as the documentation says) does not run at all when the box is not visible (basic setup page, minimized application) even though the application is active. I haven't gone through the old documentation to find out if this behavior is new; doesn't matter, I need to fix this anyway.
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

Maybe the stack trace will help a little? I just got this in the standalone program without the debugger, after leaving the program unfocused for a while, running. Screenshot also attached.

Code: Select all

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Out of memory.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
   at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
LitePlacer
    Assembly Version: 1.0.5856.22847
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/LitePlacer/LitePlacer.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34270 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
AForge.Video.DirectShow
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.0
    CodeBase: file:///C:/LitePlacer/AForge.Video.DirectShow.DLL
----------------------------------------
AForge.Video
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.0
    CodeBase: file:///C:/LitePlacer/AForge.Video.DLL
----------------------------------------
System.Web.Extensions
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Extensions/v4.0_4.0.0.0__31bf3856ad364e35/System.Web.Extensions.dll
----------------------------------------
System.Web
    Assembly Version: 4.0.0.0
    Win32 Version: 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
MemLeak3.png
MemLeak3.png (55.32 KiB) Viewed 5992 times
thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Memory Leak

Post by thereza »

yeah, you need to clean up graphics objects after you create/use them. the original code regenerated quite a few graphic objects then ignored them causing leaks like those. try the rmod version of the code.
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

As noted, this is a bit more complicated that just disposing items when done. And I hate when I don't see what the customers are seeing. dc37, since you can run it from the sources, what do you see on todays commit?
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

JuKu - did you push the commit? I only see the commit from Jan 15, 2016. On that commit, I see the same red "X" box for the camera frame.
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

dc37 wrote:JuKu - did you push the commit? I only see the commit from Jan 15, 2016. On that commit, I see the same red "X" box for the camera frame.
I did now. :oops:
dc37
Posts: 25
Joined: Thu Jan 14, 2016 6:37 pm

Re: Memory Leak

Post by dc37 »

Got the commit. It seems to be mostly stable on idle - I let it sit for about 3 hours just now, and it seems like there is no memory leak (mem usage stable at about ~30MB). I'll try running it on some large place jobs and see how that goes.

:D
mrandt
Posts: 407
Joined: Mon Apr 27, 2015 10:56 am
Location: Stuttgart, Germany

Re: Memory Leak

Post by mrandt »

Well, the "fix" for the memory leak basically ruined camera handling in latest release.

With my setup the program became pretty much unusable - find details here:
https://github.com/jkuusama/LitePlacer-DEV/issues/40

I used Karl's fork (based on thereza's work) more extensively because of that and found that there are no camera switching issues whatsoever (both pictures are always shown, maybe that's easier?).

Also, the memory consumption seemed pretty stable around 71M without significant increase over time.

Maybe it is worthwhile analysing the differences?
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Memory Leak

Post by JuKu »

I think the latest release fixed this. (<rant> Once more, one of those "works for me, not for customers" -cases. I really should have an XP, a Vista and a w7 machine - but don't have room for these, so unlikely to happen. </rant> )
vonnieda
Posts: 30
Joined: Sun Jan 03, 2016 7:05 pm

Re: Memory Leak

Post by vonnieda »

JuKu wrote:I think the latest release fixed this. (<rant> Once more, one of those "works for me, not for customers" -cases. I really should have an XP, a Vista and a w7 machine - but don't have room for these, so unlikely to happen. </rant> )
JuKu,

I invested in a copy of VMWare and copies of the all the OSes I need to test on. It saves me a ton of time and desk space. Might be worth looking into.

I prefer VMWare over VirtualBox, even though it's not free, because it's USB support is far better, which is important when working on a PnP machine :)

Jason
Post Reply