473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Memory not GCing after form closes

First time posting, hope I can provide enough information that this makes sense. Sorry if this gets verbose, but I am sure someone will ask me an unrelated question before helping me, so I figure I might as well explain it all now.

I am a Jr. developer at a small company working in as sort of an apprentice to an older developer (coding for 30+ years). The program is for internal use by employees as a ticket tracking system running as a front end for a SQL database. I noticed recently that a small group of users will periodically (once a week) get memory exceptions, so I got a profiling tool to look into the problem. I am having trouble working with the wealth of information it is supplying, and unfortunately the problem is not yet a large enough concern to my lead developer for him to pull away from his current project. I am hoping to be able to handle this without forcing him to stop what he is doing.

The Problem:
A commonly used form (MDI child) to view/edit tickets does not collect ANY of the gen 2 memory it is consuming when it is closed within a reasonable amount of time. It eventually must collect, or this issue would be affecting everyone, but in the shorter tests I have done (10-15 minutes) it does not collect at all.

The profiler shows that the largest remnant from the form is datarows, referenced by the MDI parent from through a System.Windows.Forms.PropertyStore+ObjectEntry[]. I've read that this is due to .net not collecting the last MDI child. However, even if I open 3 forms, then close them all, none of the memory from ANY of them releases. The memory use in gen 2 just continues to grow. Gen 0 and 1 collect.

In the MDI parent a dataset that stores a number of tables used for relations is copied by this MDI child form so that we aren't making continuous calls to the SQL server for them. I think this may be what the reference that is keeping the form alive is. I am not sure though. If this is the case, how do I remove this reference when or after closing the form?

If this is not the case, how can I find what is being referenced?

I know that is a lot, I appreciate any help you guys can give.
Sep 24 '10 #1
11 4125
hype261
207 100+
Just because the form closes doesn't mean that the objects for the form are going to be Garbage Collected. Garbage collection occures when ever the CLR feels it is necessary, but you can request to have a Garbage Collection run using.

Expand|Select|Wrap|Line Numbers
  1. GC.Collect();
  2. GC.WaitForPendingFinalizers();
I would put this in your code after the form is closed and see if it frees up memory. It definitely seems like you are holding on to memory somewhere though.
Sep 25 '10 #2
I tried that, and it did not affect the memory pool.

I know that that it is holding onto memory somewhere, a reference from the MDI parent remains even after the form has dispose() called on it.

I need some help understanding how to locate the reference, and/or how to destroy it.
Sep 27 '10 #3
I really feel like, based on the memory profiler's information, that the cause is these datasets.

The MDI parent gets a bunch of tables from a SQL server when the program starts, and puts them in a dataset. The MDI Child uses dataset.copy() to get them without accessing the SQL server.

Does using copy() create a reference to the MDI parent form? If so, how do I break this reference?
Sep 27 '10 #4
Not sure if bumping works in this forum, may have to repost.
Oct 1 '10 #5
GaryTexmo
1,501 Expert 1GB
What does your parent form do with the datasets after it copies them to the child?

Or do you think the child is hanging around as well, resulting in more memory allocated every time a child is opened, then never released? By that I mean, if you keep opening and closing child forms, memory usage ramps up?
Oct 1 '10 #6
What you need to do on form close is call the Dispose method for the Dataset not the Form. Something like ds.Dispose(). That will release it at that time.
Oct 1 '10 #7
The parent form holds the datasets until the program closes, as the child is a commonly used form. However, the copy is done in the child form by accessing the public datasets in the parent.

And yes, the memory usage keeps ramping up, I believe the child windows are hanging around. The memory profiler stats that dispose() has been called on the form and datasets/rows that are there, but that doesn't stop them from remaining live in Gen 2 memory for some reason.

@Michael: I have tried that, it did not seem to have an effect.

Thanks for the response guys =)
Oct 1 '10 #8
Have you tried ds.Dispose() on the Child and the Parent?
Oct 1 '10 #9
hype261
207 100+
Have you tried instead of doing dataset.copy just passing a reference of the dataset to your child window? MSDN leads me to believe that .copy does a deep copy of the dataset and that could be held on to by something.
Oct 1 '10 #10
If I call dispose() on the parent, then it might GC. The reason we do this copy is to maintain the Parent for the life of the application so that calling a select/fill from the database is not needed multiple times.

If a reference is passed, then the parent datasets will be changed by the parent. The reason for the copy is to allow the datasets to be worked with and databound to the child form.

If you are right about copy holding on to something, how can it be let go? I have been thinking that something like that has been the problem, but I don't know how to fix it.
Oct 4 '10 #11
GaryTexmo
1,501 Expert 1GB
Is there a way you can boil this down to a simple test to experiment with? I usually like to isolate the problem in a separate solution... in this case I'd manually create a small dataset, then try copying it and loading it on another form. If I can reproduce it in this smaller scale, I can then attack the problem and experiment with solutions with comfortable in the knowledge that I have fewer external factors.

It also means I (and by I, I mean you) can post the code on a forum so people can help me debug ;)

I wonder if it would be worthwhile for you to write your own copy method in order to ensure you're making duplicates and not accidentally keeping any references around. I'd try this on the smaller scale project first, I'd imagine a manual dataset copy could be a big bit of code.
Oct 4 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Nothing | last post by:
I have a form that opens. On this form there is information along with a button that opens a payment form. The payment form opens and I enter a payment type, cash check or charge, a payment...
2
by: Ken | last post by:
Hello, I have a small VB.NET form that I open with a showdialog. When it closes, the entire mdi form flashes. This app is developed with VS 2003 and runs on Windows 2000. Any suggestions...
0
by: AussieRules | last post by:
Hi, I have a form(shown as a showdialog), and when it unloads, I get the following. There is no code in the unload event. What would be the cause ? External component has thrown an exception
3
by: RD | last post by:
Dim myfrm as new frmb myfrm.show() Dim myfrm2 as new frmc myfrm2.show Opens two forms from a butom located on forma when I close forma I would like both form myfrm and for myfrm2 to close...
13
by: Edwin Smith | last post by:
I have a form which displays a DataGridView table generated with the VS2005 tools. The database is a Pervasive v.9 with an ODBC driver. The DataGridView works great except when I'm done and I...
4
by: Luke Bailey | last post by:
I'm trying to complete some changes to a database that I have created and I need to finish it by tomorrow morning! Here's the situation: I have a form where people can order a number of...
4
kcdoell
by: kcdoell | last post by:
I have a form (Form1) that displays records based on 3 unbound combo boxes that are also on my form. My record source for this form is a query “ReQryForecast” (which looks at those combo boxes via...
9
lotus18
by: lotus18 | last post by:
Hello folks I have a form with textboxes to input and it is showed as modal form (form 1.showDialog). I created a validation for my form and it should not save unless all the fields are filled up...
11
Sl1ver
by: Sl1ver | last post by:
Hi I got a main form and a database selection form. When someone selects the select database form, a new form opens up. I want to be able to see when that for is closed and then send a popup...
6
Belimisimus
by: Belimisimus | last post by:
On close command I have code which ask me if I want to save changes before closing (yes, no, cancel). Private Sub Close_Click() bSaving = True If Me.Dirty Then answer =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.