Memory management question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    Memory management question

    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:

    rtbBrowseEntryB ody.SelectionFo nt = 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

  • Peter Bromberg [C# MVP]

    #2
    RE: Memory management question

    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
    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Paul" wrote:
    [color=blue]
    > 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:
    >
    > rtbBrowseEntryB ody.SelectionFo nt = 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
    >
    >[/color]

    Comment

    • Craig Deelsnyder

      #3
      Re: Memory management question

      On Fri, 13 Jan 2006 12:35:18 -0600, Paul <Gef.Mongoose@g mail.com> wrote:
      [color=blue]
      > 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:
      >
      > rtbBrowseEntryB ody.SelectionFo nt = 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
      >[/color]

      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.

      --
      Craig
      Microsoft MVP - ASP/ASP.NET

      Comment

      Working...