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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:57:39+00:00 2026-06-14T14:57:39+00:00

In the following code: public void f() { List l1<int> = new List<int>(); List

  • 0

In the following code:

public void f() 
{
    List l1<int> = new List<int>();
    List l2<int> = new List<int>();
    //.. populate l1 and l2
    ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
    {
       // use l1 and l2
       // force gc.collect l1 and l2?
    }));
    //..
}

l1 and l2 are Thread local very large lists. When do they become eligible for garbage collection? When the thread is done executing the block, do they become eligible?

Is it a good idea to force garbage collection of l1 and l2 when the thread is done with them?

thanks

  • 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-14T14:57:40+00:00Added an answer on June 14, 2026 at 2:57 pm

    First off, calling GC.Collect only schedules a garbage collection. If something is still being referenced, then it will still not be collected.

    As to your answer, I believe that these will be collected once they are not referenced any longer, which would require that the delegate be completed and not referenced anymore.

    So, if it is a simple usage, I believe that the delegate will be cleaned up when it completes, which will then allow the lists to be cleaned up

    However, you might fall into a trap where the anonymous delegate is not cleaned up, but I think the ThreadPool should deal with this. If not, then you might be interested in this SO, especially Rory’s answer

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

Sidebar

Related Questions

i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: public void BeginConvert(object data) { ConverterData cObject = (ConverterData)data;
Considering following code public class A { public static void main(String[] args) { new
I have the following code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_database); db=new DBAdapter(this);
Given the following code : public void insertIntoQueue(float length,int xElement,int yElement,int whichElement) { Dot
I have the following code: public void DeleteAccountsForMonth(int year, int month) { var result
There is the following code: @Override public void showDialog(final Context context) { AlertDialog.Builder builder=new
I have the following code: public void disconnect() { running = false; if(thread !=
I have the following code: public void Dispose() { bool append = true; using(var
I have the following code: public void post(String message) { final String mess =

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.