473,396 Members | 2,033 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,396 software developers and data experts.

Dispose Generic List

I have filled generic list with data on one form.
When I close form generic list stay in memory waiting GC to collect.
I want to implement code on form close to dispose generic list.
Jul 25 '07 #1
3 12096
On Jul 25, 12:46 pm, "Radenko Zec" <logic_rab...@hotmail.comwrote:
I have filled generic list with data on one form.
When I close form generic list stay in memory waiting GC to collect.
I want to implement code on form close to dispose generic list.
Calling Dispose won't collect any memory. You could call GC.Collect
when you close the form, after making sure you no longer have any
references to the data. GC.Collect is generally not worth calling, but
when closing a form it may be reasonable.

Jon

Jul 25 '07 #2
On Wed, 25 Jul 2007 04:56:15 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote:
Calling Dispose won't collect any memory. You could call GC.Collect
when you close the form, after making sure you no longer have any
references to the data. GC.Collect is generally not worth calling, but
when closing a form it may be reasonable.
Maybe. Though, I have to say...before I actually did any .NET
programming, I inferred all sorts of resource-management headaches caused
by garbage collection that would require calls to the GC.Collect() method,
all of which turned out to be non-issues once I started doing actual .NET
stuff.

When you have unmanaged stuff that has to be released at a specific point
in time, there's the Close() and/or Dispose() paradigm to take care of
that. For anything else, you really just don't care about something being
released. In neither case does GC.Collect() need to be called explicitly.

The one exception I can think of is after a form shown using ShowDialog()
has been closed or the form is an MDI form (both of these are mentioned
specifically in the docs for Form.Close()), and IMHO explicitly calling
Dispose() or using the "using" statement is better than calling the GC
directly. And of course this scenario doesn't relate directly to the
original post anyway, since they are not talking about unmanaged resources
(the managed List<will be automatically released at such time as the
memory is needed).

Pete
Jul 25 '07 #3
Peter Duniho <Np*********@nnowslpianmk.comwrote:
Calling Dispose won't collect any memory. You could call GC.Collect
when you close the form, after making sure you no longer have any
references to the data. GC.Collect is generally not worth calling, but
when closing a form it may be reasonable.

Maybe. Though, I have to say...before I actually did any .NET
programming, I inferred all sorts of resource-management headaches caused
by garbage collection that would require calls to the GC.Collect() method,
all of which turned out to be non-issues once I started doing actual .NET
stuff.

When you have unmanaged stuff that has to be released at a specific point
in time, there's the Close() and/or Dispose() paradigm to take care of
that. For anything else, you really just don't care about something being
released. In neither case does GC.Collect() need to be called explicitly.

The one exception I can think of is after a form shown using ShowDialog()
has been closed or the form is an MDI form (both of these are mentioned
specifically in the docs for Form.Close()), and IMHO explicitly calling
Dispose() or using the "using" statement is better than calling the GC
directly. And of course this scenario doesn't relate directly to the
original post anyway, since they are not talking about unmanaged resources
(the managed List<will be automatically released at such time as the
memory is needed).
The reason why it may be worth calling GC.Collect after a form is
closed is that in that special situation you *may* know more than the
garbage collector does - that a lot of memory is now reclaimable, even
if a lot of that memory was due to object in generation 2.

I'd love to claim that these were my original thoughts, but they're not
- they're the thoughts of someone rather smarter, Rico Mariani:

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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 25 '07 #4

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

Similar topics

11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
3
by: Maxim | last post by:
Hi! According to documenation, if we need to release some umanaged resources manually, we need to implement IDisposable interface with single Dispose method. I am just wondering, what will...
14
by: Jonas | last post by:
Hi! I'm developing the middletiers of an ASP.NET application in VB.NET. I've got a business logic layer in which I would like to perform auditing to a database. Instead of making an auditing...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
0
by: Wiktor Zychla [C# MVP] | last post by:
We do have generic classes, methods and delegates. My question is: what reason prevents us from having generic properties and indexers? // impossible public List<T> GetList<T> { get { ... }
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
2
by: Henri.Chinasque | last post by:
I have a feeling this is a dumb one, but here it is: IEnumerator<Timplements IDisposable, but the thing is I'm not sure what I'm supposed to dispose! I'm also curious why IEnumerator<T>...
10
by: Miro | last post by:
I have created myself an issue, and perhaps my idea wasn't as bright as I thought it was originally. If someone can help me figure out what the correct train of thought should be - or if there is...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.