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

How to dispose ContextMenus

Hi,
I found out, that a simple Form, created only with the designer, wont
Dispose its contextmenu if you show the form, right-click it, and dispose
the form afterwards.
This isnt really what I expected and causes some huge memory-leaks in my
app.

All works fine, if I add the ContextMenu to the form.components manually.
(funny, the designer tells me not to modify the InitializeComponent(), but
since it works so stupid, I'll have to)

To me this doens't look like how it's meant to be, so can somebady please
tell me how it should work?

Regards,
Michael Sander
Apr 26 '06 #1
5 3697
Michael,

..NET 2.0 context menu strips are added to the form's components collection,
thus disposed along with the form.
..NET1.x context menus are not, but is it a big deal? How manu context menus
do you have to worry about? Thei will be eventually disposed by the
finalizer.
If you want them disposed, though, don't change the InitializeComponent
method. In the constructor after the call to this method add a line(s) to
add this components to the form
s *componets* collection.
--
HTH
Stoitcho Goutsev (100)
"Michael Sander" <sp**@h3c.de> wrote in message
news:Ou*************@TK2MSFTNGP03.phx.gbl...
Hi,
I found out, that a simple Form, created only with the designer, wont
Dispose its contextmenu if you show the form, right-click it, and dispose
the form afterwards.
This isnt really what I expected and causes some huge memory-leaks in my
app.

All works fine, if I add the ContextMenu to the form.components manually.
(funny, the designer tells me not to modify the InitializeComponent(), but
since it works so stupid, I'll have to)

To me this doens't look like how it's meant to be, so can somebady please
tell me how it should work?

Regards,
Michael Sander

Apr 26 '06 #2
Thanks, that helps.

As for the big deal: i got overriden Components all over wich refer objects
like lists, records, fields and commands, all pending on each other. Thus an
not freed ContextMenu means not freeing tons of data.

Now I'll have to check with every component if the desinger works correct or
not :(

"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP05.phx.gbl...
Michael,

.NET 2.0 context menu strips are added to the form's components
collection, thus disposed along with the form.
.NET1.x context menus are not, but is it a big deal? How manu context
menus do you have to worry about? Thei will be eventually disposed by the
finalizer.
If you want them disposed, though, don't change the InitializeComponent
method. In the constructor after the call to this method add a line(s) to
add this components to the form
s *componets* collection.

Apr 26 '06 #3
Michael,

Dispose is meant to be used for releasing unmanaged resources. It has noting
to do with managed ones. That is when you call dispose you don't free the
memory in the managed heap. That memory will become free when the GC
happens. If you keep references to managed objects you don't need to worry
about thinks like setting references to null for example.
For example if you have object A that references objects B and C you don't
need to implement Dispose in A that sets the reference to B and C to null.
As long as A is not referenced any more and there is no other references to
B and C, but only the one that A holds, the three of them will be garbage
collected when GC kicks off.

This is just a remark.
--

Stoitcho Goutsev (100)

"Michael Sander" <sp**@h3c.de> wrote in message
news:Oh***************@TK2MSFTNGP02.phx.gbl...
Thanks, that helps.

As for the big deal: i got overriden Components all over wich refer
objects like lists, records, fields and commands, all pending on each
other. Thus an not freed ContextMenu means not freeing tons of data.

Now I'll have to check with every component if the desinger works correct
or not :(

"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP05.phx.gbl...
Michael,

.NET 2.0 context menu strips are added to the form's components
collection, thus disposed along with the form.
.NET1.x context menus are not, but is it a big deal? How manu context
menus do you have to worry about? Thei will be eventually disposed by the
finalizer.
If you want them disposed, though, don't change the InitializeComponent
method. In the constructor after the call to this method add a line(s) to
add this components to the form
s *componets* collection.


Apr 26 '06 #4
yeah, i now.

But it just doesnt works with that ContextMenu. Alle Objects beeing
referenced are managed, the GC.Collect is called manually a couple of time
for testing, no references from outside go to that silly Menu.
So in this case I or better the containing form MUST call
ContextMenu.Dispose.
Odd enough.

Thanks for your help,
Michael Sander

"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP04.phx.gbl...
Michael,

Dispose is meant to be used for releasing unmanaged resources. It has
noting to do with managed ones. That is when you call dispose you don't
free the memory in the managed heap. That memory will become free when the
GC happens. If you keep references to managed objects you don't need to
worry about thinks like setting references to null for example.
For example if you have object A that references objects B and C you don't
need to implement Dispose in A that sets the reference to B and C to null.
As long as A is not referenced any more and there is no other references
to B and C, but only the one that A holds, the three of them will be
garbage collected when GC kicks off.

This is just a remark.
--

Stoitcho Goutsev (100)

"Michael Sander" <sp**@h3c.de> wrote in message
news:Oh***************@TK2MSFTNGP02.phx.gbl...
Thanks, that helps.

As for the big deal: i got overriden Components all over wich refer
objects like lists, records, fields and commands, all pending on each
other. Thus an not freed ContextMenu means not freeing tons of data.

Now I'll have to check with every component if the desinger works correct
or not :(

"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP05.phx.gbl...
Michael,

.NET 2.0 context menu strips are added to the form's components
collection, thus disposed along with the form.
.NET1.x context menus are not, but is it a big deal? How manu context
menus do you have to worry about? Thei will be eventually disposed by
the finalizer.
If you want them disposed, though, don't change the InitializeComponent
method. In the constructor after the call to this method add a line(s)
to add this components to the form
s *componets* collection.



Apr 26 '06 #5

Michael Sander wrote:
Hi,
I found out, that a simple Form, created only with the designer, wont
Dispose its contextmenu if you show the form, right-click it, and dispose
the form afterwards.
This isnt really what I expected and causes some huge memory-leaks in my
app.

All works fine, if I add the ContextMenu to the form.components manually.
(funny, the designer tells me not to modify the InitializeComponent(), but
since it works so stupid, I'll have to)

To me this doens't look like how it's meant to be, so can somebady please
tell me how it should work?


In case you missed my post in your last thread:

<http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/764815931aa14ff9>
<http://tinyurl.com/frdsv>

In shot: This looks like it was an 'oversight' in 1.1; it's fixed in
2.0.

--
Larry Lard
Replies to group please

Apr 26 '06 #6

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

Similar topics

1
by: Stefan De Schepper | last post by:
Hi all, Do I have to explicitly dispose all disposable objects? For some obscure reason I see for instance brushes or graphics been disposed, but never contextmenus and such. Can anyone explain...
3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
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...
10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
16
by: Daniel Mori | last post by:
If an object implements the IDisposable interface (regardless if its a framework object or a user object), should I always dispose of that object out of principle?
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...
2
by: PromisedOyster | last post by:
I like what Microsoft has done with their ContextMenus on their bowser based WindowsLive email (formerly hotmail). Does anyone know how they acheived this? Are there any third party products...
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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...

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.