473,721 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Garbage Collection

Hi all, lets get start.

i have a few questions to ask perhaps someone can help me.
i´m doing a simple aplication. some thing like this
i have a form with a button that opens another form in dialog mode.

' button code ...
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()

first , when the application start, it uses (ex 17 mb of memory see using
the windows taskmanager), and after i close the dialog form, it uses even
more memory.
is there any sample that shows how realy gc works, i need to save memory not
spend an waiting for a stupid function todo his job.

second. when i use a form and open inside a function , the finaliza method
is never called. why ? see below ..

private sub Button1_click (...... )
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()
end sub

i think it is suposed after the end sub, it calls the finalise of the
frmAbout ??? or It is'nt ?? the finalise is never called in this situation.
:(
what is microsoft thinking when they do the GC.

thks
JSB
Jul 21 '05 #1
8 1706
Hello,
first , when the application start, it uses (ex 17 mb of memory see using
the windows taskmanager), and after i close the dialog form, it uses even
more memory.
Don't trust the taskmanager. Instead use either a CLR Profiler or check the
performance counter.

second. when i use a form and open inside a function , the finaliza method
is never called. why ? see below ..


By Finalizer you mean the destructor? That is not called when you call
dispose yourself.

Finalizers are very expensive, because the GC has to promote objects to
finalize to the next generation on the heap and run the finalizer. The
memory can only be reclaimed until the GC has run the next time.
Greetings,
Henning
Jul 21 '05 #2

"João Santa Bárbara" <jo****@i24port ugal.com> wrote in message
news:OC******** ********@tk2msf tngp13.phx.gbl. ..
Hi all, lets get start.

i have a few questions to ask perhaps someone can help me.
i´m doing a simple aplication. some thing like this
i have a form with a button that opens another form in dialog mode.

' button code ...
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()

first , when the application start, it uses (ex 17 mb of memory see using
the windows taskmanager), and after i close the dialog form, it uses even
more memory.
is there any sample that shows how realy gc works, i need to save memory
not spend an waiting for a stupid function todo his job.


' button code ...
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()
frm = nothing
gc.Collect()

This will reduce the memory. In a fat client application, when you _know_
that the managed heap is mostly garbage, and you want to keep it from
getting any bigger, feel free to force a garbage collection.

David
Jul 21 '05 #3
check out Rico's blog, this guy knows what he is talking about....

http://blogs.msdn.com/ricom/archive/...29/271829.aspx

HTH

Ollie Riches

"João Santa Bárbara" <jo****@i24port ugal.com> wrote in message
news:OC******** ******@tk2msftn gp13.phx.gbl...
Hi all, lets get start.

i have a few questions to ask perhaps someone can help me.
i´m doing a simple aplication. some thing like this
i have a form with a button that opens another form in dialog mode.

' button code ...
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()

first , when the application start, it uses (ex 17 mb of memory see using
the windows taskmanager), and after i close the dialog form, it uses even
more memory.
is there any sample that shows how realy gc works, i need to save memory not spend an waiting for a stupid function todo his job.

second. when i use a form and open inside a function , the finaliza method
is never called. why ? see below ..

private sub Button1_click (...... )
Dim frm As New frmAbout
frm.ShowDialog( Me)
frm.Dispose()
end sub

i think it is suposed after the end sub, it calls the finalise of the
frmAbout ??? or It is'nt ?? the finalise is never called in this situation. :(
what is microsoft thinking when they do the GC.

thks
JSB

Jul 21 '05 #4
Henning,
Are you sure that destructors are not called when you call a Dispose
yourself. I think this is done only when you GC.SuppressFina lize() from the
Dispose method that this happens.

--
http://dotnetjunkies.com/weblog/dotnut
"Henning Krause [MVP]" <ne**********@s pam.infinitec.d e> wrote in message
news:Ov******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
first , when the application start, it uses (ex 17 mb of memory see using the windows taskmanager), and after i close the dialog form, it uses even more memory.
Don't trust the taskmanager. Instead use either a CLR Profiler or check

the performance counter.

second. when i use a form and open inside a function , the finaliza method is never called. why ? see below ..


By Finalizer you mean the destructor? That is not called when you call
dispose yourself.

Finalizers are very expensive, because the GC has to promote objects to
finalize to the next generation on the heap and run the finalizer. The
memory can only be reclaimed until the GC has run the next time.
Greetings,
Henning

Jul 21 '05 #5

"Ranjan" <ra************ *@gmail.com> wrote in message
news:O2******** ******@TK2MSFTN GP14.phx.gbl...
Henning,
Are you sure that destructors are not called when you call a Dispose
yourself. I think this is done only when you GC.SuppressFina lize() from
the
Dispose method that this happens.
A destructor is not called when a Dispose method is called - internally in
..NET they have nothing to do with each other.

When an object is no longer reachable via a root and a garbage collection
cycle occurs, the GC determines that the object has a finalizer and puts the
object on a special finalizer queue. This is serviced by a thread that runs
in the background. After the finalizer for the object has run and the next
GC cycle has occurred the memory is reclaimed.

When a Dispose method is called all that happens is that a method (called
Dispose) is invoked on the object; the intent of this method is to cleanup
the object (whatever that means). It does not involve the finalizer at all.
Typically after an object has been disposed it should not be used again -
however, this is not a requirement, it is a convention.

Quite often the Dispose method also calls GC.SuppressFina lize(). This has
the effect of removing the object from the list of objects that require
finalization so that the extra GC cycle to reclaim the memory does not
occur. However, calling GC.SuppressFina lize() from the Dispose method is not
done by the CLR, nor is it a requirement, it is only a convention that most
programmers follow.

For example, if a Dispose is called on an object but GC.SuppressFina lize()
is not called, and the object remains reachable, then the Finalizer is never
called and the memory is never reclaimed. Conversely, if the object is no
longer reachable then at the next GC cycle the Finalizer gets queued, and on
the following GC it is called, even if the Dispose method is never called.

This proves that the two operations are unrelated unless specifically tied
together via user logic.




--
http://dotnetjunkies.com/weblog/dotnut
"Henning Krause [MVP]" <ne**********@s pam.infinitec.d e> wrote in message
news:Ov******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
> first , when the application start, it uses (ex 17 mb of memory see using > the windows taskmanager), and after i close the dialog form, it uses even > more memory.


Don't trust the taskmanager. Instead use either a CLR Profiler or check

the
performance counter.
>
> second. when i use a form and open inside a function , the finaliza method > is never called. why ? see below ..
>


By Finalizer you mean the destructor? That is not called when you call
dispose yourself.

Finalizers are very expensive, because the GC has to promote objects to
finalize to the next generation on the heap and run the finalizer. The
memory can only be reclaimed until the GC has run the next time.
Greetings,
Henning


Jul 21 '05 #6
Exactly my thoughts

--
http://dotnetjunkies.com/weblog/dotnut


"David Levine" <no************ ******@wi.rr.co m> wrote in message
news:uh******** ******@TK2MSFTN GP12.phx.gbl...

"Ranjan" <ra************ *@gmail.com> wrote in message
news:O2******** ******@TK2MSFTN GP14.phx.gbl...
Henning,
Are you sure that destructors are not called when you call a Dispose
yourself. I think this is done only when you GC.SuppressFina lize() from
the
Dispose method that this happens.
A destructor is not called when a Dispose method is called - internally in
.NET they have nothing to do with each other.

When an object is no longer reachable via a root and a garbage collection
cycle occurs, the GC determines that the object has a finalizer and puts

the object on a special finalizer queue. This is serviced by a thread that runs in the background. After the finalizer for the object has run and the next
GC cycle has occurred the memory is reclaimed.

When a Dispose method is called all that happens is that a method (called
Dispose) is invoked on the object; the intent of this method is to cleanup
the object (whatever that means). It does not involve the finalizer at all. Typically after an object has been disposed it should not be used again -
however, this is not a requirement, it is a convention.

Quite often the Dispose method also calls GC.SuppressFina lize(). This has
the effect of removing the object from the list of objects that require
finalization so that the extra GC cycle to reclaim the memory does not
occur. However, calling GC.SuppressFina lize() from the Dispose method is not done by the CLR, nor is it a requirement, it is only a convention that most programmers follow.

For example, if a Dispose is called on an object but GC.SuppressFina lize()
is not called, and the object remains reachable, then the Finalizer is never called and the memory is never reclaimed. Conversely, if the object is no
longer reachable then at the next GC cycle the Finalizer gets queued, and on the following GC it is called, even if the Dispose method is never called.

This proves that the two operations are unrelated unless specifically tied
together via user logic.




--
http://dotnetjunkies.com/weblog/dotnut
"Henning Krause [MVP]" <ne**********@s pam.infinitec.d e> wrote in message
news:Ov******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

> first , when the application start, it uses (ex 17 mb of memory see

using
> the windows taskmanager), and after i close the dialog form, it uses

even
> more memory.

Don't trust the taskmanager. Instead use either a CLR Profiler or check

the
performance counter.

>
> second. when i use a form and open inside a function , the finaliza

method
> is never called. why ? see below ..
>

By Finalizer you mean the destructor? That is not called when you call
dispose yourself.

Finalizers are very expensive, because the GC has to promote objects to
finalize to the next generation on the heap and run the finalizer. The
memory can only be reclaimed until the GC has run the next time.
Greetings,
Henning



Jul 21 '05 #7
I got the context wrong it think.
What Henning wrote was it is not inherent that a destructor is called when a
Dispose is called.
I misunderstood, misread the "not" part. Sorry.
--

"Ranjan" <ra************ *@gmail.com> wrote in message
news:Og******** ******@tk2msftn gp13.phx.gbl...
Exactly my thoughts

--
http://dotnetjunkies.com/weblog/dotnut


"David Levine" <no************ ******@wi.rr.co m> wrote in message
news:uh******** ******@TK2MSFTN GP12.phx.gbl...

"Ranjan" <ra************ *@gmail.com> wrote in message
news:O2******** ******@TK2MSFTN GP14.phx.gbl...
Henning,
Are you sure that destructors are not called when you call a Dispose yourself. I think this is done only when you GC.SuppressFina lize() from the
Dispose method that this happens.
A destructor is not called when a Dispose method is called - internally in .NET they have nothing to do with each other.

When an object is no longer reachable via a root and a garbage collection cycle occurs, the GC determines that the object has a finalizer and puts

the
object on a special finalizer queue. This is serviced by a thread that

runs
in the background. After the finalizer for the object has run and the next GC cycle has occurred the memory is reclaimed.

When a Dispose method is called all that happens is that a method (called Dispose) is invoked on the object; the intent of this method is to cleanup the object (whatever that means). It does not involve the finalizer at

all.
Typically after an object has been disposed it should not be used again - however, this is not a requirement, it is a convention.

Quite often the Dispose method also calls GC.SuppressFina lize(). This has the effect of removing the object from the list of objects that require
finalization so that the extra GC cycle to reclaim the memory does not
occur. However, calling GC.SuppressFina lize() from the Dispose method is

not
done by the CLR, nor is it a requirement, it is only a convention that

most
programmers follow.

For example, if a Dispose is called on an object but GC.SuppressFina lize() is not called, and the object remains reachable, then the Finalizer is

never
called and the memory is never reclaimed. Conversely, if the object is no longer reachable then at the next GC cycle the Finalizer gets queued, and on
the following GC it is called, even if the Dispose method is never

called.
This proves that the two operations are unrelated unless specifically tied together via user logic.




--
http://dotnetjunkies.com/weblog/dotnut
"Henning Krause [MVP]" <ne**********@s pam.infinitec.d e> wrote in message news:Ov******** ******@TK2MSFTN GP10.phx.gbl...
> Hello,
>
> > first , when the application start, it uses (ex 17 mb of memory see using
> > the windows taskmanager), and after i close the dialog form, it uses even
> > more memory.
>
> Don't trust the taskmanager. Instead use either a CLR Profiler or check the
> performance counter.
>
> >
> > second. when i use a form and open inside a function , the finaliza
method
> > is never called. why ? see below ..
> >
>
> By Finalizer you mean the destructor? That is not called when you call> dispose yourself.
>
> Finalizers are very expensive, because the GC has to promote objects to> finalize to the next generation on the heap and run the finalizer. The> memory can only be reclaimed until the GC has run the next time.
>
>
> Greetings,
> Henning
>
>



Jul 21 '05 #8
Yes, thats right. But most Dipose() method make a call to
SuppressFinaliz e().

Greetings,
Henning Krause [MVP]
=============== ===========
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
"Ranjan" <ra************ *@gmail.com> wrote in message
news:O2******** ******@TK2MSFTN GP14.phx.gbl...
Henning,
Are you sure that destructors are not called when you call a Dispose
yourself. I think this is done only when you GC.SuppressFina lize() from the Dispose method that this happens.

--
http://dotnetjunkies.com/weblog/dotnut
"Henning Krause [MVP]" <ne**********@s pam.infinitec.d e> wrote in message
news:Ov******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
first , when the application start, it uses (ex 17 mb of memory see using the windows taskmanager), and after i close the dialog form, it uses even more memory.


Don't trust the taskmanager. Instead use either a CLR Profiler or check

the
performance counter.

second. when i use a form and open inside a function , the finaliza method is never called. why ? see below ..


By Finalizer you mean the destructor? That is not called when you call
dispose yourself.

Finalizers are very expensive, because the GC has to promote objects to
finalize to the next generation on the heap and run the finalizer. The
memory can only be reclaimed until the GC has run the next time.
Greetings,
Henning


Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2331
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and then throws them away and then monitors the garbage collection and store statistics on it, preferably in C#. I want to know what is the longest period of time that an application may lock up while garbage collection is processing. Thanks!
6
810
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
11
2726
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind this? Is it because C is generally a 'low level' language and they didn't want garbage collection to creep into C++ and ruin everything? Just wondering :)
34
6424
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple, probably a few hundred lines of code in Python. There is a need to interact with network using the socket module, and then probably a need to do something hardware- related which will get its own driver written in C.
5
3610
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000 measurement exactly 10 ms apart. In the future this may decrease to 5ms ). I am concerned that if garbage collection invokes during this time it may interfere with our measurement results. I have looked over the garbage collection mechanism and see no...
8
3042
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by the mainline. The class that instantiated the object in question is definitely still in existence at the point garbage collection swoops in and yanks it out from under my processing. Is there a way to ensure an instantiated object cannot be freed...
28
3176
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will this work be library based or language based and will it be based on that of managed C++? Then of course there are the finer technical questions raised (especially due to pointer abuse). Is a GC for C++ just a pipe dream or is there a lot of work...
56
3705
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application = null; Private Microsoft.Office.Interop.Outlook.NameSpace _Namespace = null; The Constructor: public OutlookObject()
350
11780
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use one, and in what percentage of your projects is one used? I have never used one in personal or professional C++ programming. Am I a holdover to days gone by?
158
7816
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.