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

When to use IDispose

If I have a class which wraps a class which implements IDisposable,
should I implement IDisposable, too, in the wrapping class, and call
the wrapped class Dispose() from the wrapping class Dispose()?

E.g.

Public Class Widget : IDisposable
{
private DisposableObject disposableObject;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
disposableObject.Dispose()
}
}
~Widget()
{
Dispose(false);
}

Nov 17 '05 #1
2 1473
yes. if you read .net framework library documentation, the example in the
IDisposable.Dispose() method does same thing as yours. (example uses
private Component component; rather then DisposableObject. this is the only
difference with yours)
Nov 17 '05 #2
I think I must be having an off-day - I didn't spot the sample code in
there until your reply made me go and look again!

Thanks very much

SSG

Nov 17 '05 #3

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

Similar topics

3
by: JP | last post by:
Ok, Im at my wits end with trying to dispose of this class. Everything I try either doesnt dispose the class or I get build error. Im using C#. What Im I doing wrong? XHTML_Library...
9
by: Alvin Bruney [MVP] | last post by:
with the using construct, exit from scope calls dispose on said object. But what happens in a connection pooling scenario? Is the run-time smart enough to realize that Object Pooling is being used...
15
by: Sam Sungshik Kong | last post by:
Hello! A disposable object's Dispose() method can be called either explicitly by the programmer or implicitly during finalization. If you call Dispose, the unmanaged resources are released...
3
by: JP | last post by:
Ok, Im at my wits end with trying to dispose of this class. Everything I try either doesnt dispose the class or I get build error. Im using C#. What Im I doing wrong? XHTML_Library...
15
by: Barry Flynn | last post by:
VB 2005. I have the following code in a Sub. Dim oFred As SillyClass oFred = New SillyClass oFred.Gloop() oFred = Nothing Exit Sub
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.