I am using a tablelayoutpanel
with 128 cells that can be populated randomly with a panel that contains a picturebox
and a textbox
. What is the best practice to remove all panels with picturebox
and textbox
before repopulating the tablelayoutpanel
? If not done properly, will there be memory leaks?
Asked
Active
Viewed 2,044 times
1
-
1Yes. You *have* to call the panel's Dispose() method. Which will also remove it from the TLP. Any child controls inside the panel are automatically disposed. – Hans Passant Jan 13 '13 at 21:13
-
You may need to manually remove the image from the PictureBox first during an override of the Dispose(). It can continue to hold onto the reference to the image file. I ran into an issue with something like this on a project a year or two ago, and had to do that because it was causing issues with trying to delete the source file. It's just something to consider depending on what you're doing. – krillgar Jan 13 '13 at 21:28
-
check this http://stackoverflow.com/a/2014427/1080742 – spajce Jan 13 '13 at 21:52