Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2007, 12:40 PM
Registered User
 
Join Date: Sep 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Memory leak - MDI form?

I have a standard VB Form with a button. The button opens a new MDI form. If I open the MDI form and then open several (blank) child forms then close the MDI form, the Memory slowly creeps up. I've tried using GC.COLLECT() to free up the memory after closing the MDI form but no joy.

Is there anything else I could try (or should be doing) to prevent this memory leak?

Thanks


 
Old September 4th, 2007, 01:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. well.. you could try dispose all the open forms in the unload event of the mdi form...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 4th, 2007, 01:24 PM
Registered User
 
Join Date: Sep 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you be more specific in terms of the code you'd use to dispose the child forms and by the term "unload event"???

Here's what I've been trying (in the "FormClosing" event of the MDI)
(Note: All child forms are owned by the MDI form)

    Private Sub MDIParent1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

        Dim frm As Form

        For Each frm In Me.OwnedForms
            frm.Close()
            frm = Nothing
        Next frm

        GC.Collect()
    End Sub

 
Old September 4th, 2007, 01:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

instead of frm = nothing, better you do something like frm.dispose... also don't call the GC by your own, it will recall the memory by itself an it's a expensive call to do...

are you disposing the objects you are using in every form also???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 4th, 2007, 02:29 PM
Registered User
 
Join Date: Sep 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Using Dispose instead didn't change the behaviour. Here's where I notice the memory buildup:

If I close the child form down manually (e.g. mouse click on upper right-hand corner X) then close the MDI form down, the Memory goes back to normal. If close down the MDI form manually (e.g. mouse click the upper right-hand corner) whilst the child form is still open then the memory stays up.

Regarding disposing objects - the memory build up happens even if there are no controls/objects on the child forms. However I did incorporate disposing of all objects on each child form as a precaution. Still no luck though.

Thx.


 
Old September 4th, 2007, 02:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

looks like you are not alone with this problem
http://www.thescripts.com/forum/thread650021.html

anyway... try move you code to formclosing event.. but even that it can take a while till GC collect it...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak in a loop neilsands Java Basics 4 March 17th, 2010 05:59 AM
Looking for Memory Leak Advice Bill_Thompson Visual C++ 0 October 16th, 2007 05:42 PM
IE Memory Leak Jman82 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 6th, 2006 05:22 PM
Memory Leak in ADO Seeja Pro VB Databases 1 December 27th, 2004 07:28 PM
Think I have a memory leak, need advice grantmeans Classic ASP Databases 1 March 12th, 2004 03:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.