disposing of an object

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I use a 3rd party grid throughout my apps. My customers are losing memory
each time they open one of the grids. I call
me.c1truedbgrid.dispose()
each time the window closes, but the memory is not released. Is there
something else I should be doing to dispose of this object and reclaim the
lost memory? I've contacted c1 but no answer from them yet.

Thanks for any help.

Bernie Yaeger
 
If this 3rd party control is a COM object, then yes, you must call:

Marshall.RealeaseCOMObject(obj)
 
Bernie,

Dispose does never release memory.

The only thing it does is giving the GC a signal that it in your opinion can
be released. However, the GC will check for that again and if it can not be
released it stays.

Reasons for the last can be a reference to an existing object or an
reference from an existing object.

Cor
 
Bernie Yaeger said:
I use a 3rd party grid throughout my apps. My customers are losing memory
each time they open one of the grids. I call
me.c1truedbgrid.dispose()
each time the window closes, but the memory is not released. Is there
something else I should be doing to dispose of this object and reclaim the
lost memory? I've contacted c1 but no answer from them yet.

Is this a .NET control or an ActiveX control? In addition to that you may
want to use a memory profiler to check if the memory occupied by the process
as shown in task manager is really used. Check out
'GC.WaitForPendingFinalizers' + 'GC.Collect' for debugging purposes too.

Allocation Profiler src
<URL:http://www.gotdotnet.com/Community/...mpleGuid=3254325d-a4aa-4bb3-aa86-c72d5104ec74>

CLR Profiler for the .NET Framework 2.0
<URL:http://www.microsoft.com/downloads/...1c-3870-43be-8926-862b40aa0cd0&displaylang=en>

CLR Profiler (v2.0)
<URL:http://www.microsoft.com/downloads/...52-D7F4-4AEB-9B7A-94635BEEBDDA&displaylang=en>
 
Cor Ligthert said:
Dispose does never release memory.

Sure, it can. It can release unmanaged resources (and thus memory), but
this depends on the implementation of the 'Dispose' method.
The only thing it does is giving the GC a signal that it in your opinion
can be released. However, the GC will check for that again and if it can
not be released it stays.

No, it doesn't signal the GC anything. 'Dispose' can simply contain code to
clean up unamanged resources such as file handles, unmanaged memory which
has been allocated, ...).
Reasons for the last can be a reference to an existing object or an
reference from an existing object.

More specifically: If the object can be reached from within the
application, then the object doesn't get cleaned up. Circular references
between objects which cannot be reached any more don't prevent the GC from
removing the objects from memory. Sample:

A <-> B <- Application
(Circular reference between A and B, objects can be reached by
the application, thus A and B are not removed by the GC.)

A <-> B Application
(Circular reference between A and B, objects cannot be reached
by the application because the reference has been removed, thus
A and B could be potentially removed by the GC.)
 
Dispose does never release memory.

Well, not Dispose directly, but very often unmanaged resources are released
inside it. That's the purpose of Dispose, to have a place to indicate that
the object should release its references to unmanaged resources.
 
Herfried,

I know, however for me the question was: why is the datagrid not released?

Reading it, it can be explained in another way too.

Cor
 
Scott,
Well, not Dispose directly, but very often unmanaged resources are
released inside it. That's the purpose of Dispose, to have a place to
indicate that the object should release its references to unmanaged
resources.

In the each other passing post time, I had already answered in the way you
wrote, that was before I saw your message.

It is confirm your reply to me.

:-)

Cor
 
Bernie said:
I use a 3rd party grid throughout my apps. My customers are losing memory
each time they open one of the grids. I call

How are you verifying this?
I've contacted c1 but no answer from them yet.

Good luck with that, their customer support is not very good. They
seem to never return e-mails. They have a forum where you can post
questions, but they never seem to get any official response there
either. I abandonded their products because of it.
 
Hi Cor,

Thanks for your reply.

This is a .net component. Is it possible that using dispose will help
eventually? Might the GC come around after a few minutes and dispose the
object?

Tx,

Bernie
 
Hi Herfried,

It is a .net control. The memory is really used: when my customer opens too
many of these (closing each before opening another), he runs out of memory
and his system freezes up. I have verified this by looking at tak manager,
pf usage. It continues to rise, never diminishes, unless you boot exit the
app.

Thanks for your help.

Bernie
 
Calling Dispose() has no effect on when the GC will clean your object. Are
you calling the Marshall.ReleaseCOMObject(obj) method?
 
Bernie Yaeger said:
It is a .net control. The memory is really used: when my customer opens
too
many of these (closing each before opening another), he runs out of memory
and his system freezes up. I have verified this by looking at tak
manager,
pf usage. It continues to rise, never diminishes, unless you boot exit
the
app.

It's likely a bug in the component which only the manufacturer can fix.
 
Back
Top