Memory management question

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi all,

I'm still learning about dispose()'ing of resources and i'm curious if
there is anything I should do in the following circumstance:

rtbBrowseEntryBody.SelectionFont = new Font(<font info>);

By using the 'new' keyword i'm allocating memory. Should I do anything
to free this memory after the section which needs it is finished? Or
should it just be left to GC? Or should I not be using such statements,
but something else.

Any help would be appreciated,

Paul
 
In general, you do not need to worry about Dispose unless an object
implements IDisposable and has a Dispose method, or if you have an object you
are writing that holds onto unmanaged resources.

The Garbage Collector takes care of all this for you. When an object is out
of scope and is no longer referenced, the Garbage man sees it's been put out
to the street and picks it up.
Peter
 
Hi all,

I'm still learning about dispose()'ing of resources and i'm curious if
there is anything I should do in the following circumstance:

rtbBrowseEntryBody.SelectionFont = new Font(<font info>);

By using the 'new' keyword i'm allocating memory. Should I do anything
to free this memory after the section which needs it is finished? Or
should it just be left to GC? Or should I not be using such statements,
but something else.

Any help would be appreciated,

Paul

General rule I've heard and follow is don't get involved in
disposing/finalizing unless it's a large, memory-intensive object where
it'd be beneficial to reclaim memory as quickly as possible, or if it's a
reference to an unmanaged component.
 
Back
Top