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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:43:39+00:00 2026-05-27T10:43:39+00:00

I have a function that takes in a list of functors: public void RunFunc(List<Func<double,

  • 0

I have a function that takes in a list of functors:

public void RunFunc(List<Func<double, double>> functorList)

The thing is that the Func<double, double> are assigned with methods from different objects. My concern now is that the garbage collector would always hold pointers to these methods, and always hold the memory for those objects because the GC doesn’t know how to dispose them.

Am I right? Will RunFunc cause memory leak? If yes, what I should do to free the memory that are held by List<Func<double, double>> functorList?

  • 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-27T10:43:40+00:00Added an answer on May 27, 2026 at 10:43 am

    You are creating a list of delegates, and while this list exists it will hold a reference to every object that each delegate references.

    If the RunFunc method stores this list as a member, than the objects will not be garbage collected as long as the list is stored. This is a good thing – otherwise it might later try calling a function on an object that has been destroyed.

    As soon as the list stops being referenced it will no longer be preventing the objects from being garbage collected.

    So, in answer to your question, RunFunc really isn’t any different from any other CLR method, and the same garbage collection rules will apply as always.

    Here’s a simpler example:

    Action myAction = null;
    {
       var widget = new Widget();
       myAction = () => { widget.ScooblyWob() }; 
    }
    // the widget object has gone out of scope, but will stay in memory
    // It is not a candidate for garbage collection, because 
    // it is being referenced by the myAction function.
    
    myAction(); 
    // Even though I have no explicit references to the widget, 
    // I just called a function on it!
    
    myAction = null;
    // Now the action has been dereferenced, 
    // so the widget is a garbage collection candidate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple function that takes a list of comma separated (x,y)
I have a function that takes pointer to pointer to struct. struct ABC; void
I have a function that takes a list and replaces some elements. I have
i'm new in Haskell. I have to write function that takes list of Integers
I have a Python function that takes a list as a parameter. If I
I have a function that takes a list of floats and returns the same
I have to make a function that takes an empty list as first argument
I have this function below that takes a list of id's and searches the
I have a function that takes a list that either has two or three
Say I have a function that takes a list and does something: (defun foo(aList)

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.