Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report for Bug 33390 on
GitHub or Developer Community if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
Created attachment 12643 [details]
Application demonstrating issue & Profiling results
I am developing an long lived application, that ideally should not have to restart for weeks. It was originally developed for C# Visual Studio to run under Windows. But since taking up the project I have ported it to Mono under Debian Linux. Because of this and the size of the application, I continued to use Windows.Forms to save rewriting all the UI in GTK. During system testing before release a memory leak was noticed, and I have narrowed it down to be that Controls and Forms are not getting completely disposed of, even though I am calling Dispose() on them.
I created a simple application to see if it was my code or something in Mono, and I can't see any more ways of releasing the memory, so I am guessing something in the Windows.Forms is hanging on to the references. The application works by creating a main form, which displays the Process.GetCurrentProcess().WorkingSet64 in the Form.Text property. When you click on this form it spawns another form, which has 50 empty labels in it, so you see the leak a bit easier. Clicking on this form, will close it, then the main form will dispose of this form and redisplay the current memory usage. By clicking on these forms to open one then close it and repeat, the memory usage steadily climbs.
I have attached the application I created to demonstrate this issue to this bug report, with the results from heapshot profiling every 5 seconds, as a comment below the C# code. This report was generate by running the application with heapshot profiling enabled, and constantly clicking on the forms to create and destroy forms.
Mono 4.0.5, Raspberry PI, Linux.
- Application compiled under Visual Studio 2012 using Visual basic and Framework 4.0.
- The main window of an application uses a PictureBox. Each time the property PictureBox.image is changed, about 300kb are lost. Some hours later, the system kills the app because the memory is full.
- I have tried different ways of filling PictureBox.image without any success.
I think that we experience the same issue.
I have worked out that your probably not going to get a reply from the developers here. From what I have read, they have ceased development of WinForms as have Microsoft. I ended up rewriting the GUI in GTK#, which fixed the issue, and the GUI is also a bit quicker.
Have you tried manually disposing the PictureBox.Image before changing it? Make sure you disposing of everything correctly (every disposable object, should be in a using statement or have .Dispose() called on it in all code paths), including where you load the image. If you think its a bug, your probably on your own with fixing it as well, but I was able to use the PictureBox with an images generated using NPlot with no memory leaks, I think ...
Use the Profiler to see what objects are actually leaking: http://www.mono-project.com/docs/debug+profile/profile/profiler/
Yes I have tried "image.dispose" each time I load a new one but it does not change anything.
You say that they cease working on winforms but they bring a lot of nice features (datagridview) which are very usefull on the RPi. I need a cross platform compatibility and GTK is not so much mu cup of tea. I do need to switch on XAML ?
Will try the profiler, thank you.
Thanks for your help.
Tested under VC and C#, same behaviour :-(
In fact the image is linked to a field of a database. Each time the table is refreshed, the image changes, loosing at least 300kb...
This does not occur under Windows with Visual studio.
VB, not VC...
problem solved with version 4.2 on Raspberry no more leaking :-))