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 8426737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:36:40+00:00 2026-06-10T04:36:40+00:00

Working in .Net 2.0, moving the code base to 4.0 soon Recently I have

  • 0

Working in .Net 2.0, moving the code base to 4.0 soon

Recently I have been working with serializing classes with events, and finding my event subscribers (i.e. a Form) would attempt to serialize too (I am using [field:NonSerializable] now to stop this).

This got me to thinking, if I pass a delegate to a static class’s method (to be used method scope only), does the static class root the delegate’s owner, causing it to be uncollectable by GC?

I have a static ListUtilities class doing the job of lambda expressions, as well as static caches, that I regularly pass delegates, and wondering if this could be leaking memory?

  • 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-06-10T04:36:42+00:00Added an answer on June 10, 2026 at 4:36 am

    No, nothing to worry about there. Passing a delegate to a method is fine, (unless that method stores the delegate somewhere indefinitely).

    What is problematic, though is static events (or events on long-lived objects, such as singletons). If you don’t unsubscribe those, then the event can keep the object alive forever. For example:

    // this object is meant to be short-lived
    var obj = new SomeType();
    
    // some static event
    MyUtility.SomeEvent += { obj.Foo(); };
    

    now the static event on MyUtility prevents the new SomeType instance from being collected until that event subscription is removed… which it probably never will be, since it is an anonymous method (which need voodoo to unsubscribe).

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

Sidebar

Related Questions

I've been working with .NET for a number of years, but recently I've been
I have a working .Net WCF HTTP service. If I put the URL into
I'm working with .NET strongly-typed datasets and have a table with a nullable int
I am currently working with .Net 2.0 and have an interface whose generic type
I'm working with code I'm converting to Pgsql working with .NET. I want to
I'm an experienced developer who has been working with .Net for the last 5
I am working on ASP.NET MVC3. I have a partial view RestaurantAdminNavigation.ascx which i
I'm struggling with trying to get this piece of code working properly. I'm moving
I have a strong preference for working in code, leverage IntelliSense and opening up
I have a C#.Net console app code that transfers files between linux and windows

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.