473,467 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Memory leak advice needed

I use 3-d party component. In this component I must pass a reference to my
object. The problem is that this component has an ugly bug.When this
component is disposed, it incorrectly don't delete the reference to my
object from one of its shared lists.And since the operation repeats many
times the leak is huge.
Is there a way to kill my object anyway?
Thanks a lot,
Boni
Nov 23 '05 #1
13 1508
"Boni" <oilia@nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I use 3-d party component. In this component I must pass a reference to my
object. The problem is that this component has an ugly bug.When this
component is disposed, it incorrectly don't delete the reference to my
object from one of its shared lists.And since the operation repeats many
times the leak is huge.
Is there a way to kill my object anyway?
Thanks a lot,
Boni


You should contact that 3rd party provider.... have you tried passing a
reference to Nothing? Depending on how that 3rd party component works,
passing a ref to Nothing may clear the circular dependency.... then again,
it may raise an error (which you should be able to trap)

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Nov 23 '05 #2
The 3-d party provider is Microsoft :). I am speeking about a memory leak
when I create a context menue items dynamically
(http://weblogs.asp.net/pwilson/archi...20/77451.aspx). They are not
disposed until the form is disposed.
It is documented bug and there is a workaround for that (using reflection).
But in general, somehow I don't see the reason of garbadge collection.
Before I started with it I was sure that it completely solve all memory leak
problems. But it seems, that it creates a new class of memory leak problems,
where you must think very much about all your references. And even then
there is no insurance that something went wrong because of 3-d party bugs.
I mean, .NET is a perfect libruary, easy to use. But the memory leak problem
should be revised once more. Currently there is even no appropriate software
which can automatically check those bug's (a-la bounds checker). For me
there was no problem to kill all created objects myself in c++. There are
coding guidlines and problem is quite managable. But in .NET I spend all my
time by looking for memory leaks, it is even more time then debugging. And I
am still not sure, when the debug level is acceptable.
Is it only my problem or all of you have it too?

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> schrieb im Newsbeitrag
news:u4**************@tk2msftngp13.phx.gbl...
"Boni" <oilia@nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I use 3-d party component. In this component I must pass a reference to my
object. The problem is that this component has an ugly bug.When this
component is disposed, it incorrectly don't delete the reference to my
object from one of its shared lists.And since the operation repeats many
times the leak is huge.
Is there a way to kill my object anyway?
Thanks a lot,
Boni


You should contact that 3rd party provider.... have you tried passing a
reference to Nothing? Depending on how that 3rd party component works,
passing a ref to Nothing may clear the circular dependency.... then again,
it may raise an error (which you should be able to trap)

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..

Nov 23 '05 #3
I saw the fix below in one of the MIcrosoft articles for MainMenu (they
apparently can also have the same memory leak problems as Context Menus so I
would assume this fix would also apply them them as well but not sure)

For any forms that have MainMenu components, add the following code to make
sure the components are disposed of correctly:
Protected Override Sub Dispose(disposing as boolean)
If disposing
If not components is Nothing
components.Dispose()
components = Nothing
If not mainMenu1 is Nothing
‘Code to add
mainMenu1.Dispose()
mainMenu1 = Nothing
base.Dispose(disposing)
End If
End If
End If

--
Dennis in Houston
"Boni" wrote:
The 3-d party provider is Microsoft :). I am speeking about a memory leak
when I create a context menue items dynamically
(http://weblogs.asp.net/pwilson/archi...20/77451.aspx). They are not
disposed until the form is disposed.
It is documented bug and there is a workaround for that (using reflection).
But in general, somehow I don't see the reason of garbadge collection.
Before I started with it I was sure that it completely solve all memory leak
problems. But it seems, that it creates a new class of memory leak problems,
where you must think very much about all your references. And even then
there is no insurance that something went wrong because of 3-d party bugs.
I mean, .NET is a perfect libruary, easy to use. But the memory leak problem
should be revised once more. Currently there is even no appropriate software
which can automatically check those bug's (a-la bounds checker). For me
there was no problem to kill all created objects myself in c++. There are
coding guidlines and problem is quite managable. But in .NET I spend all my
time by looking for memory leaks, it is even more time then debugging. And I
am still not sure, when the debug level is acceptable.
Is it only my problem or all of you have it too?

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> schrieb im Newsbeitrag
news:u4**************@tk2msftngp13.phx.gbl...
"Boni" <oilia@nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I use 3-d party component. In this component I must pass a reference to my
object. The problem is that this component has an ugly bug.When this
component is disposed, it incorrectly don't delete the reference to my
object from one of its shared lists.And since the operation repeats many
times the leak is huge.
Is there a way to kill my object anyway?
Thanks a lot,
Boni


You should contact that 3rd party provider.... have you tried passing a
reference to Nothing? Depending on how that 3rd party component works,
passing a ref to Nothing may clear the circular dependency.... then again,
it may raise an error (which you should be able to trap)

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..


Nov 23 '05 #4
> The 3-d party provider is Microsoft :). I am speeking about a memory leak
when I create a context menue items dynamically


The logic below works for me with context menus built by my programs:

Dim cm As ContextMenu
' your code goes here to create cm including click event handler(s)
cm.Show(up to you, up to you)
Application.DoEvents() ' needed to raise and process the click event
cm.Dispose() ' required, else memory leak

Nov 23 '05 #5
Boni,

What do you think that dispose does?

Cor
Nov 23 '05 #6
Hi Amerser,
Why are u so sure? Have you checked with a profiler. This logic don't works
because of MS bug (in .NET 1.1.). There is still a static reference inside
of form (which you didn't created), but .NET did. So your cm will not be
disposed untill a form is disposed. Hope I don't disappoint you:). Take a
profiler and look yourself.
"AMercer" <AM*****@discussions.microsoft.com> schrieb im Newsbeitrag
news:32**********************************@microsof t.com...
The 3-d party provider is Microsoft :). I am speeking about a memory leak
when I create a context menue items dynamically


The logic below works for me with context menus built by my programs:

Dim cm As ContextMenu
' your code goes here to create cm including click event handler(s)
cm.Show(up to you, up to you)
Application.DoEvents() ' needed to raise and process the click event
cm.Dispose() ' required, else memory leak

Nov 23 '05 #7
Wellcome in club you have the same memory leak, but you don't know about it.
"AMercer" <AM*****@discussions.microsoft.com> schrieb im Newsbeitrag
news:32**********************************@microsof t.com...
The 3-d party provider is Microsoft :). I am speeking about a memory leak
when I create a context menue items dynamically


The logic below works for me with context menus built by my programs:

Dim cm As ContextMenu
' your code goes here to create cm including click event handler(s)
cm.Show(up to you, up to you)
Application.DoEvents() ' needed to raise and process the click event
cm.Dispose() ' required, else memory leak

Nov 23 '05 #8
Hi Cor, hi all,
I know about dispose and try to explicitely call it, but as you see, for
examle with context menus this don't prevent memory leak.
In general,my point is following.
IMHO it is much harder to find memory leaks in .NET. There are no tools for
this, and application don't crash. I miss a possibility to find such bugs.
(profiler can't really help if your app creates and disposed many objects,
you can't manually filter out correced objects from leaked objects. A have
programmed many years C++ and there are programming rules and tools which
allow to minimize memory leak (in my whole carrier the leak finding time was
not higher then a development time). But in .NET it is very hard to attack
memory leak problems. This is absolutely manual and time consuming process,
which kills .NET productivity win. The problem in .NET is even bigger
(IMHO), then in unmanaged code. If you don't deleted only 1 reference the
whole chain of objects can stay undeleted and you will even NOT notice it.
I think, that we need some possibility, at least to automatically detect
exact point of memory leaks. (but so far I have no idea how it would be
possible)
Are you agree with me or is it only my problem and nobody except me has it.
Thanks a lot for your opinions,
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb im Newsbeitrag
news:Of**************@TK2MSFTNGP11.phx.gbl...
Boni,

What do you think that dispose does?

Cor

Nov 23 '05 #9
Just a tip, when I suspect an object for memory leak, I do a simple program
to test it, within a for i as integer = 0 to 10000 or something, so you can
see if that is really the object causing the problem..
- Fredrik

"Boni" <oilia@nospam> wrote in message
news:O7**************@TK2MSFTNGP11.phx.gbl...
Hi Cor, hi all,
I know about dispose and try to explicitely call it, but as you see, for
examle with context menus this don't prevent memory leak.
In general,my point is following.
IMHO it is much harder to find memory leaks in .NET. There are no tools
for this, and application don't crash. I miss a possibility to find such
bugs. (profiler can't really help if your app creates and disposed many
objects, you can't manually filter out correced objects from leaked
objects. A have programmed many years C++ and there are programming rules
and tools which allow to minimize memory leak (in my whole carrier the
leak finding time was not higher then a development time). But in .NET it
is very hard to attack memory leak problems. This is absolutely manual and
time consuming process, which kills .NET productivity win. The problem in
.NET is even bigger (IMHO), then in unmanaged code. If you don't deleted
only 1 reference the whole chain of objects can stay undeleted and you
will even NOT notice it.
I think, that we need some possibility, at least to automatically detect
exact point of memory leaks. (but so far I have no idea how it would be
possible)
Are you agree with me or is it only my problem and nobody except me has
it.
Thanks a lot for your opinions,
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb im Newsbeitrag
news:Of**************@TK2MSFTNGP11.phx.gbl...
Boni,

What do you think that dispose does?

Cor


Nov 23 '05 #10
> Why are u so sure? Have you checked with a profiler. This logic don't works
because of MS bug (in .NET 1.1.). There is still a static reference inside
of form (which you didn't created), but .NET did. So your cm will not be
disposed untill a form is disposed. Hope I don't disappoint you:). Take a
profiler and look yourself. Wellcome in club you have the same memory leak, but you don't know about it.


No - no such leak. I know it works for two reasons. First, I don't
associate the cm with a form - no form contains a "static reference" to the
cm. Form.ContextMenu is Nothing throughout all my operations, and tying a cm
to a form is an essential ingredient to the problem you are talking about.

The second reason is that I use a tool (a vb function I wrote) when I am
worried about a memory leak. The tool minimizes the working set, and it
garbage collects until diminishing returns, and it then reports memory
figures to me. The testing I did was to popup and dismiss (all ways of
dismissing) a cm many times while running the memory tool every 5 seconds or
so. The cm approach I described yields no memory growth.

Nov 23 '05 #11
No - no such leak. I know it works for two reasons. First, I don't
associate the cm with a form - no form contains a "static reference" to
the
cm. Form.ContextMenu is Nothing throughout all my operations, and tying a
cm
to a form is an essential ingredient to the problem you are talking about. neither I did.I even had no form, just a control.
Look in internet for " allCreatedMenuItems ". This is internal static
hashtable of the control class. AFAIK there is no chance to avoid the leak,
if you create CM. The reference to this CM will be added into static
hashtable of an active control, you don't have to assign something.There is
a workaround, how to free this hashtable using reflection or memory is
automatically fried, when control dies.
The second reason is that I use a tool (a vb function I wrote) when I am
worried about a memory leak. The tool minimizes the working set, and it
garbage collects until diminishing returns, and it then reports memory
figures to me. The testing I did was to popup and dismiss (all ways of
dismissing) a cm many times while running the memory tool every 5 seconds
or
so. The cm approach I described yields no memory growth.

Hmm..., ok you must know it. In any case thanks for the idea. May be I will
write something like this for all my classes.
Best wishes,
Boni
Nov 23 '05 #12
> Look in internet for " allCreatedMenuItems ".

Good idea, just finished doing that. Very interesting and very disturbing.
I thought this problem had been fixed by MS many months ago. (I'm using .net
fw 1.1 sp1, windows xp, all updates suggested by MS have been installed). In
all cases, I do

Dim mi As new MenuItem("blah blah", ClickHandler) ' always this
constructor
mi.Enabled = Enabled ' a previously computed boolean
mi.Checked = Checked ' ditto

Then, mi is added to the cm (others created and added similarly), and then
the logic proceeds as discussed in my earlier post. MenuItems are never
reused or updated in any way after they are shown, but creation is always a
new menuitem, update Enabled, and update Checked.

I don't think the 'allCreatedMenuItems' issue is biting me, and I don't know
why. It sounds from the internet discussion that it has to bite everybody.
It seems to me that MS must have fixed it within the last year or so. A
search of MS web site for 'allCreatedMenuItems' yields nothing. A search for
menuitem and leak is unproductive - they have a fix in an MDI situation.

FYI, one contributor to the discussions indicated that he thought a disabled
menuitem was an essential ingredient to creating the problem. I ran a test
with my procedures that included a disabled menuitem. No problems, no leaks.

I still think my procedures work ok, at least in my environment and with the
kinds of programs that I write. Maybe my procedures won't work in a
different setting, and that makes me nervous.

Nov 23 '05 #13
Boni,

The name "managed" code is mainly to prevent memory leaks, the Framework
should tackle that for you.

In the sample you gave the object should stay undeleted. An object should
stay as long as it has its own reference, however as well as any object is
referenced to it, what can be a long chain. Therefore are 3 types of
processes the GC to look if an object is ready to release.

If you want an explanation more in dept of this, have than a look what Willy
has written in the dotnet General newsgroup about this.

http://groups.google.com/group/micro...rch+this+group

I hope this helps,

Cor
Nov 23 '05 #14

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

Similar topics

14
by: J. Campbell | last post by:
what happens to allocated memory when a program terminates before the memory is released. For example: int main(){ int* array; int a_size = 1000; array = new int; for(int i = 0; i < a_size;...
1
by: mark.engelberg | last post by:
I am having trouble identifying the source of a memory leak in a Windows Python program. The basic gist is as follows: 1. Generate a directed graph (approx. 1000 nodes). 2. Write the graph to a...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
19
by: Jon Davis | last post by:
I'm reposting this because I really need some advice. I have a web app that makes many queries to the database on every page. In order to save development effort, I've consolidated all database...
9
by: Anton | last post by:
{Willy Skjveland} Hi, how can I trace a Memory leak in aspnet_wp.exe? {Rheena} One moment please while I search it for you. It may take me a few moments {Willy Skjveland} I need to find out...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
27
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do...
4
by: Christian Heimes | last post by:
Gabriel Genellina schrieb: Pure Python code can cause memory leaks. No, that's not a bug in the interpreter but the fault of the developer. For example code that messes around with stack frames...
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
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...
0
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,...
0
isladogs
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...
0
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...
0
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...
0
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 ...

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.