473,666 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disposing Objects?

Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and the
other forms are opened in this form. For example, in a form i fetch many
rows from the database to show them to the user on the client machine. After
this process memory gets higher but when the user closes that form the
memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect() and
GC.SuppressFina lize() method for my entities while they are being disposed.
But i cannot achieve to reduce the amount of the memory. How can i reduce
the amount of memory after the user closes the form? Is there a way to get
that result immediate after the user closes the form in C#? Thanks...
Oct 17 '06 #1
13 1933
How are you measuring the memory footprint?

Mike Ober.

"Adam Right" <ad**@right.com wrote in message
news:Ot******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the other forms are opened in this form. For example, in a form i fetch
many rows from the database to show them to the user on the client
machine. After this process memory gets higher but when the user closes
that form the memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and GC.SuppressFina lize() method for my entities while they are being
disposed. But i cannot achieve to reduce the amount of the memory. How can
i reduce the amount of memory after the user closes the form? Is there a
way to get that result immediate after the user closes the form in C#?
Thanks...


Oct 17 '06 #2
Hi Mike,

I do not understand what do you mean with Memory footprint? If you ask where
am i looking for the current memory size, i use task manager. Can you
explain in details? Thanks...

"Michael D. Ober" <obermd.@.alum. mit.edu.nospamw rote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
How are you measuring the memory footprint?

Mike Ober.

"Adam Right" <ad**@right.com wrote in message
news:Ot******** ******@TK2MSFTN GP03.phx.gbl...
>Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the other forms are opened in this form. For example, in a form i fetch
many rows from the database to show them to the user on the client
machine. After this process memory gets higher but when the user closes
that form the memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and GC.SuppressFina lize() method for my entities while they are being
disposed. But i cannot achieve to reduce the amount of the memory. How
can i reduce the amount of memory after the user closes the form? Is
there a way to get that result immediate after the user closes the form
in C#? Thanks...



Oct 17 '06 #3


On Oct 17, 10:13 am, "Adam Right" <a...@right.com wrote:
Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and the
other forms are opened in this form. For example, in a form i fetch many
rows from the database to show them to the user on the client machine. After
this process memory gets higher but when the user closes that form the
memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect() and
GC.SuppressFina lize() method for my entities while they are being disposed.
But i cannot achieve to reduce the amount of the memory. How can i reduce
the amount of memory after the user closes the form? Is there a way to get
that result immediate after the user closes the form in C#? Thanks...
Adam,

First, I just want to clarify the situations where IDisposable should
be used. Use IDisposable only for class that directly or indirectly
hold unmanaged resources. If your objects just hold information about
entities from the database then I'd bet they don't hold unmanaged
resources at all. Second, you should only be overriding the finalizer
(destructor) and calling GC.SuppressFina lize when the class directly
holds unmanaged resources. Third, GC.Collect is rarely needed. The
runtime does a pretty good job determining when the GC needs to run.
Manual calls to GC.Collect often lead to poorer performing
applications.

Are you certain these objects are no longer referenced anywhere?

Brian

Oct 17 '06 #4
Hi Brian,

Firstly i want to clarify the meaning of unmanaged and managed code. I did
not understand at all so i need help about that. Second, my baseentity has
some fields which are another entity or arraylist or hashtable. So they are
all referenced types. According to this i dispose them when the dispose
method is called but i donot dispose them when the destructor of the entity
is called. Calling GC.SuppressFina lize(entity) is done in the same manner.

On the other hand, i only call the GC.Collect() when i closes the form. I
use it in my form base. I know that GC.Collect() is not good for the
performance. But the problem is the client memory and i have to reduce the
amount of the memory after the user closes the form. In brief, all objects
that were created for the related form and its controls, must be released
after the form is closed.

For your question, how can i find the answer of "the objects are no longer
referenced anywhere?"? In C#, couldn't we release the all objects after the
related form is closed? I think we should because it is C#. Thanks...
"Brian Gideon" <br*********@ya hoo.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
>

On Oct 17, 10:13 am, "Adam Right" <a...@right.com wrote:
>Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the
other forms are opened in this form. For example, in a form i fetch many
rows from the database to show them to the user on the client machine.
After
this process memory gets higher but when the user closes that form the
memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and
GC.SuppressFin alize() method for my entities while they are being
disposed.
But i cannot achieve to reduce the amount of the memory. How can i reduce
the amount of memory after the user closes the form? Is there a way to
get
that result immediate after the user closes the form in C#? Thanks...

Adam,

First, I just want to clarify the situations where IDisposable should
be used. Use IDisposable only for class that directly or indirectly
hold unmanaged resources. If your objects just hold information about
entities from the database then I'd bet they don't hold unmanaged
resources at all. Second, you should only be overriding the finalizer
(destructor) and calling GC.SuppressFina lize when the class directly
holds unmanaged resources. Third, GC.Collect is rarely needed. The
runtime does a pretty good job determining when the GC needs to run.
Manual calls to GC.Collect often lead to poorer performing
applications.

Are you certain these objects are no longer referenced anywhere?

Brian

Oct 17 '06 #5


"Adam Right" <ad**@right.com wrote in message
news:#S******** ******@TK2MSFTN GP04.phx.gbl...
Hi Brian,

Firstly i want to clarify the meaning of unmanaged and managed code. I did
not understand at all so i need help about that. Second, my baseentity has
some fields which are another entity or arraylist or hashtable. So they
are all referenced types. According to this i dispose them when the
dispose method is called but i donot dispose them when the destructor of
the entity is called. Calling GC.SuppressFina lize(entity) is done in the
same manner.

On the other hand, i only call the GC.Collect() when i closes the form. I
use it in my form base. I know that GC.Collect() is not good for the
performance. But the problem is the client memory and i have to reduce the
amount of the memory after the user closes the form. In brief, all objects
that were created for the related form and its controls, must be released
after the form is closed.
. .
If you are going to call GC.Collect() and expect the form and all of it's
reachable objects to be collected, you need to do it _after_ the form is
closed and and no reference to the form exists from any of your application
roots.

So calling GC.Collect() from the form itself is the wrong time. You should
do it from the bit of code that created the form, after the form has been
closed and any references to the form cleared.

David
Oct 17 '06 #6
If you are going to call GC.Collect() and expect the form and all of
it's reachable objects to be collected, you need to do it _after_ the
form is closed and and no reference to the form exists from any of
your application roots.

So calling GC.Collect() from the form itself is the wrong time. You
should do it from the bit of code that created the form, after the
form has been closed and any references to the form cleared.
In addition, because a Form ultimately overrides the Object.Finalize () method
in the System.Componte ntModel.Compone nt ancestor, it will take two garbage
collections to free its memory. This is because, an object with a finalizer
is placed in a separate internal table (the "freachable " table) and survies
the first GC. See the "Finalizati on Internals" section in Jeffrey Richter's
artcile for details: http://msdn.microsoft.com/msdnmag/issues/1100/gci/

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 17 '06 #7


"Dustin Campbell" <du*****@no-spam-pleasedevexpres s.comwrote in message
news:c1******** *************** ***@news.micros oft.com...
>If you are going to call GC.Collect() and expect the form and all of
it's reachable objects to be collected, you need to do it _after_ the
form is closed and and no reference to the form exists from any of
your application roots.

So calling GC.Collect() from the form itself is the wrong time. You
should do it from the bit of code that created the form, after the
form has been closed and any references to the form cleared.

In addition, because a Form ultimately overrides the Object.Finalize ()
method in the System.Componte ntModel.Compone nt ancestor, it will take two
garbage collections to free its memory. This is because, an object with a
finalizer is placed in a separate internal table (the "freachable " table)
and survies the first GC. See the "Finalizati on Internals" section in
Jeffrey Richter's artcile for details:
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
Form.Close() calls Component.Dispo se() which calls GC.SupressFinal ize(this).
So properly closed forms will not be on the FReachable queue and will be
collected with one pass.

David

Oct 17 '06 #8
Form.Close() calls Component.Dispo se() which calls
GC.SupressFinal ize(this). So properly closed forms will not be on the
FReachable queue and will be collected with one pass.
Of course you're right. My apologies for jumping in their without thinking
it through.

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 17 '06 #9

Hi,

To achieve reducing the amount of memory to the initial value which is
before opening the form, is there a way to get this expected result after
closing the form in C#? I have tried IDisposable interface for my entities
and GC.Collect() but it did not work.

Thanks...

"Adam Right" <ad**@right.com wrote in message
news:Ot******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the other forms are opened in this form. For example, in a form i fetch
many rows from the database to show them to the user on the client
machine. After this process memory gets higher but when the user closes
that form the memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and GC.SuppressFina lize() method for my entities while they are being
disposed. But i cannot achieve to reduce the amount of the memory. How can
i reduce the amount of memory after the user closes the form? Is there a
way to get that result immediate after the user closes the form in C#?
Thanks...


Oct 18 '06 #10

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

Similar topics

1
5993
by: Egghead | last post by:
Hi all, I'm just wondering that is any way to dispose all objects when my app is shut down? I mean I can use for.. next loop to unload all loaded form when I shut down my app. Thank you, Egghead
15
3727
by: Chris Capel | last post by:
I've heard a lot of talk on the forum about memory managment in .NET and disposing things, finalizing them, garbage collection, etc. My question is which managed types need to be disposed after being used, and for which is it OK to simply let the garbage collector do its work, without worrying about calling Dispose? Is there a general rule that most don't need to be explicitly disposed, with an exception here and there? Or the other way...
4
1478
by: MC D | last post by:
Question: If I have a class which has a property which is a collection of widget objects (an arrayList of widgets), and both the containter class and the widget class implement the IDisposable interface, does the container class need to call the dispose method of each of the widgets when its dispose method is called, or does this happen automatically because the container class will go "out of scope"? Thanks for any help!
5
1352
by: Mathias L. | last post by:
I have two questions for which I couldnt find answer: If I programaticaly close DialogForm (calling Close()), is it enough or do I have to dispose it as MS.NET help says? Also, in overriden onPaint method, do I have to dispose pens, brushes and graphics object or do they got disposed by Framework?
4
1384
by: sunitabalakrishna | last post by:
Hi, Could someone explain me if I need to implement the Dispose pattern on managed objects that hold objects which have longer life or is a singleton? Example - Class A holds Class Global where Class Global is a singleton. So should Class A have
7
1143
by: Mariusz | last post by:
Hello, I have question regarding disposing objects in aspx/cs pages. If I create some objects/Arrays/ListArrays in pageLoad do I have to dispose them (by assigning the null value for objects that doesn't have dispose method). If so then where should I do this? I need to use those objects in scripts in aspx page (they are created in cs PageLoad) - so I have to dispose them after they are not needed any more. Cheers Mariusz
0
1521
by: Gman | last post by:
Hi, Objective: Draw a grid on a bitmap and set this as a panel's image. (Rather than draw the grid directly on the panel and redraw repeatedly in the paint event.) Problem: It works fine. I'm just not sure about disposing of the objects. I've tried a variety of approaches but I find that when I redraw repeatedly
4
1390
by: Rob | last post by:
Hi all, I wrote myself a little function to do my own housekeeping, I can call it by using Dispose(object) Within this function there's a select case statement which will then, based on some flags and the type of the object do things like close connections, dispose of the object where appropriate and so on.
29
2366
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but what is an unmanaged resource? Does everything need disposing? I've been using Webrequest, Webresponse, Streamreaders etc. How can I be sure of what needs disposing? Do these get automatically get disposed of at the end of the procedure...
0
8443
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, 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...
0
8866
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
8781
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
7385
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
4198
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
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
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.