Re: Memory Leak (Bitmap)Image.FromStream(memory_stream)

rgclickit <[email protected]>
Newsgroups gmane.comp.gnome.mono.devel
Message-ID <[email protected]>
Here is the code directly from the BitmapTest program:

            while (_runTest)
            {
                try
                {
                    // convert the byte[] array to a Bitmap using
Image.FromStream
                    // This will demonstrate a memory leak in Mono 4.6 and
4.8.
                    using (System.IO.MemoryStream ms = new
System.IO.MemoryStream(_sourceArray))
                    {
                        if (firstRun)
                        {
                            PaintStatus("First memory stream created OK
size: " + ms.Capacity.ToString());
                        }
                        using (Bitmap srcBitmap =
(Bitmap)Image.FromStream(ms))
                        {
                            if (firstRun)
                            {
                                PaintStatus("First Bitmap created OK size: "
+ srcBitmap.Size.ToString());
                                PaintStatus("Going to continue to run until
Stopped");
                            }
                            firstRun = false;
                        }
                    }
                    if (_forceGC)
                    {
                        GC.WaitForPendingFinalizers();
                        GC.Collect();
                    }
                }
                catch (Exception ex)
                {
                    PaintStatus("Error " + ex.Message);
                }
            }

The PaintStatus call:
        private void PaintStatus(string StatusMessage)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new status_info(PaintStatus), new object[] {
StatusMessage });
                    return;
                }
            }
            catch (Exception) { return; }

            try
            {
                string df = DateTime.Now.ToString("dd-MM hh:mm:ss");

                if (lstActivity.Items.Count > 2000)
                {
                    lstActivity.Items.RemoveAt(lstActivity.Items.Count - 1);
                }

                lstActivity.Items.Insert(0, df + " " + StatusMessage);
            }
            catch (Exception) { return; }
        }

When I started running:

<http://mono.1490590.n4.nabble.com/file/n4670336/starting.png> 

After 3 minutes of runtime from System Monitor
<http://mono.1490590.n4.nabble.com/file/n4670336/memory2.png> 


After 6 minutes of runtime from System Monitor
<http://mono.1490590.n4.nabble.com/file/n4670336/memory3.png> 

After 10 minutes of runtime from System Monitor
<http://mono.1490590.n4.nabble.com/file/n4670336/memory4.png> 

The memory keeps increasing and never drops. If I remove the memory stream
and use:

 using (Bitmap srcBitmap = (Bitmap)Image.FromFile(_file_name)) 

the memory usage doesn't change.

Again, thanks for any help you can provide.






--
View this message in context: http://mono.1490590.n4.nabble.com/Memory-Leak-Bitmap-Image-FromStream-memory-stream-tp4670327p4670336.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.dot.net/mailman/listinfo/mono-devel-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.