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

  • Home
  • SEARCH
  • 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 6096081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:53:06+00:00 2026-05-23T12:53:06+00:00

Possible Duplicates: Is it possible to have a memory leak in managed code? (specifically

  • 0

Possible Duplicates:
Is it possible to have a memory leak in managed code? (specifically C# 3.0)
Memory Leak in C#

There was a similar question on this yesterday, but for Java, so I’m interested – what it takes to create a memory leak in C# / .NET (without using unsafe) ?

  • 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-23T12:53:07+00:00Added an answer on May 23, 2026 at 12:53 pm

    static events; DEADLY, since they never go out of scope.

    static event EventHandler Evil;
    
    for(int i = 0 ; i < 1000000 ; i++)
        Evil += delegate {};
    

    The anonymous method is simply a nice-to-have here but are nice because they also are a pig to unsubscribe unless you take a copy into a variable/field and subscribe that.

    Technically this isn’t actually “leaked”, as you can still access them via Evil.GetInvocationList() – however, when used with regular objects this can cause unexpected object lifetimes, i.e.

    MyHeavyObject obj = ...
    ...
    SomeType.SomeStaticEvent += obj.SomeMethod;
    

    now the object at obj lives forever. This satisfies enough of a perceived leak IMO, and “my app died a horrible death” is good enough for me ;p

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

Sidebar

Related Questions

Possible Duplicate: General strategy to resolve Java memory leak? I have a standalone program
Possible Duplicate: how to find memory leak in c++ code/project I would like to
Possible Duplicates: Does Java have a limit on the class name length? Max name
Possible Duplicate: Java/C# method representation in memory I was wondering if i have an
Possible Duplicate: Threads synchronization. How exactly lock makes access to memory 'correct'? This question
Possible Duplicate: How does .net managed memory handle value types inside objects? I have
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
Possible Duplicates: Is it reasonable to assume my visitors have javascript enabled? How many
Possible Duplicates: C++: ptr->hello(); /* VERSUS */ (*ptr).hello(); Why does C have a distinction

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.