Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6097643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:04:02+00:00 2026-05-23T13:04:02+00:00

Inspired from this question , was wondering what are the possible ways to create

  • 0

Inspired from this question, was wondering what are the possible ways to create a memory leak in .Net. I once found one with ODBC Data Access. Has anyone had any experiences with latest version?

Edit: Are there any seemingly normal, harmless uses that can cause memory leaks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:04:03+00:00Added an answer on May 23, 2026 at 1:04 pm

    The easiest way to create a memory leak is to misuse facilities designed for interop, since they deal with unmanaged memory.

    For example, allocate a GCHandle pointing to an object, and never free it.

    Edit: Are there any seemingly normal, harmless uses that can cause memory leaks?

    Only one that I know of, particularly in some UI programs. It was possible in WinForms, but only recently became common due to WPF with MVVM:

    The key point that many people overlook is that a delegate contains a reference to the object on which it runs.

    So, if one is using a pattern such as MVVM with two-way bindings (implemented using events, comprised of delegates), and if the View is changed to a different View with the same ViewModel, by default the ViewModel’s updates remain bound to both Views, which causes a leak of the old View.

    This can in theory happen with any delegate, but in practice it’s not common because the subscriber normally outlives the publisher or unsubscribes.

    A similar situation exists when lambda event handlers are unsubscribed:

    timer.Elapsed += (_, __) => myObj.Notify();
    timer.Elapsed -= (_, __) => myObj.Notify();
    

    In this case, even though the lambda expressions are identical, they represent different handlers, so the Elapsed event will still invoke Notify. The second line above has no effect; it doesn’t unsubscribe, nor does it raise an error.

    Note that improper unsubscriptions are usually caught during testing, so they seldomly cause “leaks” in released code. In contrast, the MVVM situation above causes no observable side effects (other than a memory and resource leak).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is actually inspired from another one here on SO and I wanted
Inspired by this question and answer , how do I create a generic permutations
Inspired by this question I began wondering why the following examples are all illegal
This question is inspired from Joel's Making Wrong Code Look Wrong http://www.joelonsoftware.com/articles/Wrong.html Sometimes you
This question was inspired by one I asked almost a year ago - any-orms-that-work-with-ms-access-for-prototyping
This is inspired by this question and the comments on one particular answer in
This is more a conceptual question. It's inspired from using some extremely large table
Inspired by this question , I wanted to try my hand at the latest
G'day, Inspired by a comment I made in my answer to this question on
This is a bit of a whimsical question inspired in part by the publicity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.