Windows Develop Bookmark and Share   
 index > Windows Forms General > memory leak issues this.Invoke(new EventHandler (ReadData));
 

memory leak issues this.Invoke(new EventHandler (ReadData));

Everytime the serial port receive data event occurs, i use

Code Block

this.Invoke(new EventHandler (ReadData));

to invoke a method to parse the data streaming in on the serial port. Would this create a memory leak if the is no termination or disposing at the end of the ReadData method??

For a more detailed cope sample see post: https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2262778&SiteID=1

Thanks

Dan Walmsley  Friday, October 12, 2007 3:04 PM
Not a memory leak exactly. A memory leak is when memory keeps getting used but never gets reclaimed. In this situation, memory will keep getting used, but it will just take a while for the garbage collector to get around to reclaiming it. The effect on system memory usage is essentially the same though: it fills it up. In this case, the garbage collector will eventually get around to reclaiming that memory meaning you won't run out of memory because of this, but you very well may see a substantial performance hit since the garbage collector will be working overtime.

I replied earlier to your refernced thread in reguards to using a delegate to prevent this behavior.
Chuck the Code Monkey  Friday, October 12, 2007 4:34 PM
Not a memory leak exactly. A memory leak is when memory keeps getting used but never gets reclaimed. In this situation, memory will keep getting used, but it will just take a while for the garbage collector to get around to reclaiming it. The effect on system memory usage is essentially the same though: it fills it up. In this case, the garbage collector will eventually get around to reclaiming that memory meaning you won't run out of memory because of this, but you very well may see a substantial performance hit since the garbage collector will be working overtime.

I replied earlier to your refernced thread in reguards to using a delegate to prevent this behavior.
Chuck the Code Monkey  Friday, October 12, 2007 4:34 PM

No, this won't cause a memory leak.

Simply creating an infinite loop that calls this.Invoke(new EventHandler(SomeMethod)) shows memory usage does not continuously rise.

Peter Ritchie  Friday, October 12, 2007 6:37 PM

You can use google to search for other answers

Custom Search

More Threads

• listview sorting
• short code on filling more textboxes?
• In TabControl If AlignMent is Left or Right then TabPage text is not visible??
• need help designing master
• Clreating a Class to Interoperate with COM
• Rich Text Edit Drag and Drop
• Getting the Margins from a spooled print job?
• My MDIchild form isnt shown......
• Pixel Changed Event
• 2d charts in C# based windows form