garbage collection

G

Guest

hi,
i have a garbage collection problem. i have an application writen by
vb.net, i am opening a form and in this form there is a big query. when i
open the form, it takes 80 mb memory because of the data table. when i closed
the form it is already taking 80 mb memory. where is garbage collection? i am
waiting 30 minutes but memory usage is not decreasing. what must i do?
thanks,
Ömer KUL
 
G

Guest

hi Hederman,
i have read the article. thank you very much for your help. the article is
very helpful but it is not answering my question. i am opening a form and
memory usage is increasing(80 mb), after that i am closing it but memory
usage is not decreasing. whenever i open the form memory usage is increasing
80 mb and going on so... that is the problem...
thanks
Ömer KUL

"Sean Hederman":
 
S

Sean Hederman

If you're not holding any references to your datasets then the CLR will free
the memory when it needs to, not on some schedule. So the point would be to
ensure that the references to your datasets are being cleared.
 
R

Rob Windsor [MVP]

Task Manager doesn't always show memory usage correctly. To see this follow
these steps:

- Create a new Windows Forms application
- Run it
- Check memory usage in Task Manager
- My computer shows 15,554 K
- Minimize the app
- Check memory usage in Task Manager
- My computer shows 864 K
- Restore the app
- Check memory usage in Task Manager
- My computer shows 1,784 K

Try minimizing the app after you close the form and see if the memory usage
changes.
 
W

Willy Denoyette [MVP]

Rob Windsor said:
Task Manager doesn't always show memory usage correctly. To see this
follow these steps:

- Create a new Windows Forms application
- Run it
- Check memory usage in Task Manager
- My computer shows 15,554 K
- Minimize the app
- Check memory usage in Task Manager
- My computer shows 864 K
- Restore the app
- Check memory usage in Task Manager
- My computer shows 1,784 K

Try minimizing the app after you close the form and see if the memory
usage changes.


And what makes you think this isn't correct here?
The OS automatically reduces the workingset of a windows application
(any)when minimizing, this has been done since NT4 was introduced years ago.
Taskman takes it's values from the preformance counters, do you mean that
these aren't correct?

Willy.
 
W

Willy Denoyette [MVP]

Ömer KUL said:
hi,
i have a garbage collection problem. i have an application writen by
vb.net, i am opening a form and in this form there is a big query. when i
open the form, it takes 80 mb memory because of the data table. when i
closed
the form it is already taking 80 mb memory. where is garbage collection? i
am
waiting 30 minutes but memory usage is not decreasing. what must i do?
thanks,
Ömer KUL

When there is no garbage, there is nothing to collect, that's how the GC
works, so in your case there is no garbage because you are still holding
references to your Data Tables. Please post your code if you want to get any
more help.

Willy.
 
G

Guest

Hi Willy,
i am closing the form that increases the memory usage. are not the all
variables and controls on the form disposed? after now, does not the GC
collect them?
i can not send you all code, because it is an ERP packet and it is 50 mb
when zipped. i can send you code samples if you want.
thanks
Ömer KUL

"Willy Denoyette [MVP]":
 
J

Jon Shemitz

Ömer KUL said:
i have a garbage collection problem. i have an application writen by
vb.net, i am opening a form and in this form there is a big query. when i
open the form, it takes 80 mb memory because of the data table. when i closed
the form it is already taking 80 mb memory. where is garbage collection? i am
waiting 30 minutes but memory usage is not decreasing. what must i do?

Merely waiting won't do anything - garbage collection is triggered by
allocations, not a timer.
 
S

Sean Hederman

Ömer KUL said:
Hi Willy,
i am closing the form that increases the memory usage. are not the all
variables and controls on the form disposed? after now, does not the GC
collect them?

No, only those variables that are only referenced on the form will be
available for GC, and just because they're available doesn't mean they will
be GC'd.
 
S

Sean Hederman

Sean Hederman said:
No, only those variables that are only referenced on the form will be
available for GC, and just because they're available doesn't mean they
will be GC'd.

right away
 
N

Nick Malik [Microsoft]

Hi Omer,
i can not send you all code, because it is an ERP packet and it is 50 mb
when zipped. i can send you code samples if you want.
thanks


Typically we ask that you post only the code snippets that you believe are
causing your problem or which form a basis for you to believe that the code
"should" work. In this case, it would be helpful if you would post the
calls that fetch the data, and enough information for us to know where the
references are stored for the data (on the stack or on the heap). Also, it
would be helpful if you would post the code that occurs when you opened and
closed the form.

Notes:

80Mb is a very large amount of data. Is there any way you can reduce the
amount of data that has to be returned by being more explicit in your
queries? There is no reasonable way for me to believe that you are actually
presenting 80Mb worth of data to the user... so clearly you are returning
some data that you don't need.


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
C

Cor Ligthert

Omar,

I found the replys from Willy and Sean very clear. Now that there is a new
message added, I will try to explain their messages something more.

When you have done in by instance (I see not the code you use therefore in
VBNet)

In form1
Private myDatatable as Datatable
dim frm as new Form2
frm.datatablefrm2 = myDatatable
frm Show

And you have in your Form2
datatablefrm2 = new datatable.

Than the memory used by that datatable will released by the GC as soon as
there are no references any more in that datatable and set to nothing in
form1 (or that both forms are closed)

It is a strange way of coding by the way, however this can give the effect
you are talking about.

I hope this gives an idea

Cor
 
G

Guest

hi Willy,
i am using a variable that declared as datatable. i get data from query and
set the datatable. after i used the datatable i dispose it but the memory
usage is not decreasing. the datatable gets about 80 mb memory...
if you give me your e-mail i can send your code part.
thanks for your helps.
Ömer KUL

"Willy Denoyette [MVP]":
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top