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. 3 12124
On Jul 25, 12:46 pm, "Radenko Zec" <logic_rab...@h otmail.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
On Wed, 25 Jul 2007 04:56:15 -0700, Jon Skeet [C# MVP] <sk***@pobox.co m>
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
Peter Duniho <Np*********@nn owslpianmk.comw rote:
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.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
4-month old C#/MC++ .NET project project.
I'd like to thank in advance anyone who takes the time to read and/or
respond to this message. At a couple points, it may seem like a rant
against C# / .NET, but we are pretty firmly stuck with this approach...
|
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 happen if I just
create my own Dispose (or any other name) mehtod, without implementing
the IDisposable interface. In all the examples, which I found, this
Dispose method called from my user code (not by GC). What do I miss?
Thanks.
|
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 call in every method of my classes,
would it be a workable way to implement IDisposable in the base class to all
the BLL-classes and then in the Dispose method to do the audit call? Do I
then have to make sure that all uses of the BLL-classes end...
|
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 inside a method call.
dim myvar as new object1
object1.dosomethingmethod(new object2)
Note that object 2 has a dispose method but how do I dispose of it unless I
do the following:
|
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
{
...
}
| |
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 application that needs
implementations in both Java and C#. I have the Java side done, and
it works fantastic, and the C# side is nearly there. The problem I'm
running into has to do with the differences in implementations of
Generics between the two...
|
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>
implements IDisposable, but not IEnumerator.
Anyone?
Thanks,
HC
|
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 a solution to this one.
I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>
Public Shared frmFormsOpen() As frmMyTestForm
|
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 types derived from that base type, or arrays or generic collections of instances of types derived from that base type.
All is well until I come to the properties which are generic collections, I don't seem to be able to find an elegant way of...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |