How to free memory allocated to Form and its components?

  • Thread starter Sakharam Phapale
  • Start date
S

Sakharam Phapale

Hi All,



I made following observation of memory allocated to my application at
different stage from Windows Task Manager.



After closing the form, memory taken by application remains same.

Why doesn't memory get freed after closing the form?



Operation Memory taken by application



Load main Form. 26,000K

Load child1 form 39,000K

Close Child1 form 39,000K

Load child2 form 45000K

Close child2 form 45000K



I think on closing of form GC should free the memory allocated to the
components on that form.

Just my thought,



Any kind of help will be appreciated.



Thanks and Regards,

Sakharam Phapale
 
C

Cor Ligthert

Sakharam,

You would not look in the taskmanager for your memory behaviour. When you
search these newsgroup you will see that you are there are maybe thousand
ones, who have told what you tell as well.

You can search this newsgroups for that, however the only advises are that
you can see it better, not control it better.

The memory is freed at the best time to do that. When there is still enough
memory that is not the moment. That is one of the benefits from dotNet, that
it is not busy all the time with freeing memory, however does what it has to
do.

Here a very good document.

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

Remember when you read this that it is written by humans, so there can be
things what you can ask yourself again "is it as written, did I not see
lately other (newer) documentation which deny this".

However a very complete document in general.

I hope this helps something?

Cor
 
H

Herfried K. Wagner [MVP]

Sakharam Phapale said:
Operation Memory taken by application

Load main Form. 26,000K
Load child1 form 39,000K
Close Child1 form 39,000K
Load child2 form 45000K
Close child2 form 45000K

I think on closing of form GC should free the memory allocated to the
components on that form.

That's not always a good idea. Why free memory if nobody needs it? Keeping
the memory reserved will make the app's memory management easier. Don't
worry too much about that.
 
S

Sakharam Phapale

Hi Cor,Herfried

Thanks for your help.

It means that GC frees the memory only when application needs it.
Suppose, my application (written in .Net) has taken lot of memory and at
present doesn't need extra memory, so GC won't free it.
What if, other applications which has not written in .NET needs memory?
This will affects other applications running on computer.

I think that GC works only with applications written in .NET framework, so
it doesn't know about other applications and their memory requirement.

Just my thought.

I think I have explained my question clearly.

Regards
Sakharam Phapale
 
C

Cor Ligthert

I think that GC works only with applications written in .NET framework, so
it doesn't know about other applications and their memory requirement.
Why do you think that, why should it need to know what other programs need.
Dit you see that happen?

However I have seen that the GC runs as soon as there is some screen
painting busy so don't make it something more than it is.

Check otherwise the dotnet newsgroup on Google as I said, it is full of this
question and ends all with the same coclussions.

I saw never a message that what you stated really happened.

Just my thought,

Cor
 

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