Hello. I have a picture box on a form. The imageLocation of the picture box is set to a url like for example "http://www.google.mu/imgres?imgurl=http://1.bp.blogspot.com/-w6AJJ5Xoulg/T3AymMKbFlI/AAAAAAAAACI/EslCtw42HHg/s1600/jpeg.jpg&imgrefurl=http://zainriasat786.blogspot.com/2012/03/discuss-impact-that-file-format.html&h=480&w=640&sz=36&tbnid=fkqhzaWg8cSK4M:&tbnh=90&tbnw=120&zoom=1&usg=__54xTPooPnJOFy8xQS0TJXOtV1d8=&docid=JkpXnRk64SCIzM&hl=en&sa=X&ei=LjxoUO_uEsXRrQf28oDYBw&sqi=2&ved=0CD0Q9QEwBA&dur=24". When the form closes, we can see that memory is not released. I have added code to dispose the picture box on form closing but when I open the form again, the form crashes.
Is .Dispose() the best way to prevent memory leaks?
kirtee2209 9 Light Poster
Recommended Answers
Jump to PostJust so I'm clear, you are instantiating a new instance of your Form (i.e.
new SomethingForm();
) before each call toShowDialog();
, correct? I tried your code, and it seems to be working. Also, a stack trace is nice, but what is the actual exception you are getting (class and message)?
Jump to PostThat's what I thought from the first post, then I saw this:
viewImagesForm.ShowDialog(); if (viewImagesForm != null && !viewImagesForm.IsDisposed) { viewImagesForm.DisposeImageControls(viewImagesForm); viewImagesForm.Dispose(); viewImagesForm = null; }
where he sets
viewImagesForm
tonull
. So I wanted to know whether he was getting the reference to …
All 8 Replies
Momerath 1,327 Nearly a Senior Poster Featured Poster
kirtee2209 9 Light Poster
nmaillet 97 Posting Whiz in Training
Momerath 1,327 Nearly a Senior Poster Featured Poster
nmaillet 97 Posting Whiz in Training
kirtee2209 9 Light Poster
nmaillet 97 Posting Whiz in Training
kirtee2209 9 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.