CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Memory leak example?

  1. #16
    Join Date
    Sep 2004
    Posts
    1,361

    Re: Memory leak example?

    May I refer you to this post.

    Also, I have my PMs enabled now, so what is it you wanted to say?

    Addendum: Perhaps the mods can add the words "Memory Leak" to the bad words filter for the C# forum.
    Last edited by DeepT; November 6th, 2008 at 02:57 PM.

  2. #17
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Memory leak example?

    Quote Originally Posted by TheCPUWizard View Post
    How would that generate a leak????
    Here is my and wikipedia definition on a memory leak:
    Quote Originally Posted by Wikipedia
    In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. This condition is normally the result of a bug in a program that prevents it from freeing up memory that it no longer needs.
    If you unintentionally use up more and more memory... you got a leak.

    - petter

  3. #18
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: Memory leak example?

    Is the philosophy of .NET not to avoid mem leaks by using the Garbage Collector?

    I thought that .NET takes care about used memory and releases it, if
    required.

    So for .NET developers no memory leaks can occur.

    If I'm wrong, tell me.

  4. #19
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Memory leak example?

    Quote Originally Posted by wildfrog View Post
    Here is my and wikipedia definition on a memory leak:

    In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. This condition is normally the result of a bug in a program that prevents it from freeing up memory that it no longer needs..

    - petter
    1) NEVER trust WikiPedia...It is often a good starting point, but a many (most?) items contain at least one (typically minor) in-accuracy...

    In the case of the "dangling event", it will does not meet the criteria as it does not satisify the "no longer needs" portion.

    Code:
    1) WE sign a contract that you will notify me of certain facts when something happens.
    
    2) Time passes, and I no longer care about this, but do NOT inform you and have the contract terminated (along with any side effects of the termination)
    
    3) YOU still have the responsibility of notifying me.
    
    4) I still have the responsibility of accepting that notification.
    If I terminate my means of accdepting the notification, I would be in violation of the contract. I must (legally) keep the means of communication open.

    Now if we translate this into the "event" issue, we see the same exact condition. The object is question (the one with no references OTHER THAN the contractual reference in the delegate) is OBLIGATED to remain in existance. It is STILL REQUIRED.

    To go to a more general case, consider that EVERY object "exists" for a period of time in .NET after it is no longer needed (from the removal of the last reference to the object, until the GC runs for the generation which owns the object. From a programmers perspective, the object is "no longer needed". But this is not considered a leak....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)