Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / May 2004

Tip: Looking for answers? Try searching our database.

Dipose() problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 19 May 2004 03:21 GMT
I have a class with a public font property, I do like that

Font font;
public Font Font
{
   get
   {
       if(font == null)
           using(Form f = new Form()) // get default font !
               font = new Font(f.Font.Name, f.Size, FontStyle.Regular);
       return font;
   }
   set
   {
       if(font != null)
           font.Dispose();
       font = value;
   }
}

public void Dispose()
{
   Font = null;
}

I don't not call GC.SuppressFinalizer(this); as I don't feel the need for
Finalizer as:
1. I don't have unmanaged resource
2. having finalizer makes my object life longers, which I don't want

my problem is:
what if in my master class I have on font object and pass it to all this
'label' ?
if I change the font for one later I destroy all as they all use the same
(disposed) font ?
so I could not use dispose the font when I change it so I have to write
complex code to know if it's still in use in the main class ?
well I'm a bit lost.. I need guidance on the proper scenarii .....

Signature

ihookdb
Get your data mobile
http://www.ihookdb.com

Chad Z. Hower aka Kudzu - 19 May 2004 07:38 GMT
"Lloyd Dupont" <net.galador@ld> wrote in news:eozRJfUPEHA.1644
@TK2MSFTNGP09.phx.gbl:
> my problem is:
> what if in my master class I have on font object and pass it to all this
[quoted text clipped - 4 lines]
> complex code to know if it's still in use in the main class ?
> well I'm a bit lost.. I need guidance on the proper scenarii .....

You could add your own reference counting, but the problem you will have with
this code is that there is NO guarantee that Dispose will be called for each
instance.

What exactly are you tyring to do with your Font = null in the dispose?

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
 http://www.atozed.com/IntraWeb/

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.