|
Hey Dudes (Dudets),
I read this awesome article IDisposable: What Your Mother Never Told You About Resource Deallocation[^] and a bunch of other not so awesome ones.
However, I failed to find an answer to this question:
1. I got a base class - ObjectA that inherits from a UserControl.
2. ObjectA is then inherited from by ObjectB and tailored to particular uses elsewhere in the code. (ObjectB is not inherited from)
3. There are many different ObjectB implementations (ObjectB1....10) all of which add EventHandlers for ObjectA events and declare their own distinct events that are handled by other objects.
4. Now all ObjectBx objects are stored in a collection and then disposed off like so:
For Each oA as ObjectA in CollectionOfObjectBx
oA.Dispose
Next
5. Each ObjectBx overloads Dispose method and uses it to Remove EventHandlers.
However, these Dispose overloads never get called because instances of the ObjectBx are disposed via the base class that is not aware of anything going on inside inherited objects.
But does it matter? Want GC eventually kill off all handlers since the objects themselves are dead?
I would greatly appreciate if anyone could shed some light on this.
Regards
Alex
"All your base are belong to us..."
- Mr. Cats (2110 A.D.)
|
|
|
|
|
Hi, you need to override and not overload. all dispose methods should be called from the leaf type to the top. I think that you should clean up after your self when creating objects that are disposable. in large objects you should also set values to null explicitly to free the memory faster. The next code calls all methods when disposing:
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
//This code should go in the main
//ObjectB1 inherits from ObjectB which innhertis from ObjectA
ObjectB1 b1 = new ObjectB1();
//Calling the dispose will call the dispose of ObjectB1
//within the dispose of ObjectB1 there is a call to the base dispose.
b1.Dispose();
}
public partial class ObjectA : UserControl
{
public ObjectA()
{
InitializeComponent();
}
private void ObjectA_Load(object sender, EventArgs e)
{
}
}
public class ObjectB : ObjectA
{
public event EventHandler ObjectBEvent;
public ObjectB()
{
this.MouseClick += new MouseEventHandler(ObjectB_MouseClick);
}
void ObjectB_MouseClick(object sender, MouseEventArgs e)
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
MessageBox.Show("Dispose : ObjectB");
ObjectBEvent = null;
}
protected virtual void OnObjectBEvent(EventArgs e)
{
if (ObjectBEvent != null)
{
ObjectBEvent(this, e);
}
}
}
public class ObjectB1 : ObjectB
{
public event EventHandler ObjectB1Event;
public ObjectB1()
{
this.MouseClick += new MouseEventHandler(ObjectB1_MouseClick);
}
void ObjectB1_MouseClick(object sender, MouseEventArgs e)
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
MessageBox.Show("Dispose : ObjectB1");
ObjectB1Event = null;
}
protected virtual void OnObjectB1Event(EventArgs e)
{
if (ObjectB1Event != null)
{
ObjectB1Event(this, e);
}
}
}
Natza Mitzi
|
|
|
|
|
Hey Natza,
Thx for taking the time to answer my post. Unfortunately your solution doesn't help.
You are disposing ObjectB1 which would have worked if not for the fact that the generic dispose proc that sits in Main only knows of ObjectA and has no idea that ObjectA was inherited from.
In a word you are suggesting Top Down Dispose method calls.
But I need the Dispose methods to be called Down to Top first e.i. the last inheritor ObjectBx needs to be notified when the base class is being disposed. Once that's accomplished i can go down the inheritance tree and kill off my handlers.
Lastly, there is a twist. A few of ObejectBx's events are handled by ObjectC that is only destroyed on app shutdown.
Hence, there is a live reference remaining in memory to all ObjectBx events even after they are disposed.
"All your base are belong to us..."
- The Nameless One (2110 A.D.)
|
|
|
|
|
I think there is a workaround for this i'll post more in a bit.
"All your base are belong to us..."
- The Nameless One (2110 A.D.)
|
|
|
|
|
Hi I dont know whether I understand what you are trying to do.
Note that ObjectB1 dispose is called first even when using:
ObjectA a = new ObljectB1();
a.Dispose();
And it does not matter whether they know each other or not.
Natza Mitzi
|
|
|
|
|
Alex Feature wrote: Each ObjectBx overloads Dispose method and uses it to Remove EventHandlers.
How do you overload Dispose? I'm guessing you have public non-virtual Dispose in your base class and then methods with the same signature in all the derived classes?
If that's the case, you need to make the method that does the disposal virtual, and override it in the derived classes. That way, the Dispose calls will go the actual (runtime) types - in your case, ObjectBxs.
|
|
|
|
|
hi
I want to create asp.net
website using CMS
cms for example umbraco or DotNetNuke
database is mysql
.net 2008 express edition
IIS 5.1
can u guide me how i can start building it
i have tried with dotnetnuke and umbraco but both r problematic with mysql
and also dificult to configure
if u know any other CMS pls let me know but supportable to mysql,.net2008 express, IIS5.1
Ravie Busie
Coding is my birth-right and bugs are part of feature my code has!
|
|
|
|
|
This is a crosspost.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Come one Pete, give the guy a break. He wants to create ASP.NET. That would be good for all of use right?
[typo-caused-by-nervous-finger-energy] As I read that now I can only imagine what sort of quips you might use on that.
|
|
|
|
|
RaviBusie wrote: can u guide me
Yes, use english not text speak. If you can't bother to type the extra keys to spell "you" then most of us here that have a clue will not bother to help you.
|
|
|
|
|
Hi,
When i installed Rational clearcasetool and restarted system..and when im trying to build my vc++ application in VS 2005 im able to see the below error..
error result returned from 'cl.exe'.
Please help me out..
|
|
|
|
|
Hi,
actually i have to insert an invisible watermark in MSword files using c#.can anyone help me?
|
|
|
|
|
How do you mean "an invisible watermark"? My definition of a watermark is that of a semitransparent image displayed behind text. Obviously, semitransparent != transparent. Are you referring to permissions, which will allow only certain users to view and edit a file?
|
|
|
|
|
"invisible watermark is a process that embeds data that is not perceptible". there are different techniques which allow to embed invisible and unremovable data to images.But i want to embed invisible and unremovable data into text documents such as MS word documents using c# program.if u know anything then plz do reply me
|
|
|
|
|
Ayesha Manzoor wrote: i have to insert an invisible watermark in MSword files
I already finished your project for you. If you execute a test you will find that your requirements have been satisfied. Once you have done that we can discuss payment for services rendered.
|
|
|
|
|
Well Mike thats so nice of u.... but i want some help..not the whole project.there are some other things which i have to do in my project other then watermarking.can u give me any idea how you did???
|
|
|
|
|
Ayesha Manzoor wrote: can u give me any idea how you did???
Sure, here is how I solved the requirement of having an invisible watermark.
1) Print the document
2) Open your eyes, you cannot see the watermark because it is invisible. REQUIREMENT SATISFIED
|
|
|
|
|
Could you not generate an image with meta text.
If you look at the file format of a *.jpg or *.tiff. You might find a space to embedded it there. There is usually some header tags. Owner, author etc...
or
Depending on the image type you could create your own colour pallet. the first spot representing the color white or what ever background color. The others represent your message in char. Different color depths can increase the size of your message.
8 bit would be useful for an ascii message. 'A' 41 0101 0001
rgb could be three charactors. 'ABC' 414243
so
#000000 - white
#414243 - ABC
Might be a start
Could use 7 bit ascii and gain a few characters
or
create a style sheet with colors representing a message
For another idea:
compress your message to make it smaller and hide the message a little more
Pierce
modified on Tuesday, March 24, 2009 8:58 PM
|
|
|
|
|
should i convert .doc file into .jpg or .tiff? but then the text will not be visible.
|
|
|
|
|
The word document would stay as a word doc. You would insert a watermarked image file as an image or background.
Another idea to think about:
Why wouldn't you digitally sign your documents?
Thanks,
Pierce
|
|
|
|
|
will that watermarked image be invisible and ineditable??
and can u tel how to digitally sign a document?
Actually i have to develop a tool which will be able to water mark the word documents for copyright. to protect the document from being plagiarized. i studied different tecnhiques which are used to write some bits in between the text. but a person can edit those bits. i want something invisible and ineditable...can u give any suggestion??
|
|
|
|
|
Presently looking for code examples for LED Message Displays. There is only one presently posted and is only a numerical disply. Working with Visual Studio Pro 2005
|
|
|
|
|
You'd have to adapt the specifics of the display in the one CP article; so start reading the documentation about your display.
BTW a lot of them use the same interface spec, and actually also the same integrated circuit to instantiate it.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Greetings:
Much thanks for your timely reply. I've gone through your five articles and then to the articles where I've found the BetaBrite LED Sign API piece. Not sure if this is the article to which you refer.[a link would be most helpful] I am actually a systems administrator new to coding and this is a project I've thought up for myself. While I have your attention I would ask what would be involved in using a bluetooth headset [hardware & software] to communicate commands to an LED display. Your credentials suggest that an informed opinion is likely.
Cordially,
Phil Pense, Microsoft Certified Professional
|
|
|
|
|
Hi Phil,
I do remember reading a recent article about an LCD display[^] connected through the USB port, and an older one[^] using the parallel port. I was assuming the former was the article you were referring to.
My message basically is: any other small display is likely to be handled very similarly.
If you want my advice on what PC interface (serial, parallel, USB) would be most appropriate for your specific display device, you should give the details of make and model so I can have a quick look at the documentation. Chances are the parallel port interface is the easiest one to implement, but then parallel ports are getting rare these days, unless you use a USB-to-parallel cable.
As to your other question: I have no experience with either bluetooth or headset interfacing. What is the functionality you are looking for? If it is voice commands, I expect there are several solutions for voice recognition, and these would take voice input from a mike, whatever the connection method is; I expect a bluetooth headset to just work for input and output under Windows.
Regards,
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|