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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:43:12+00:00 2026-06-12T22:43:12+00:00

Good Day! I’m using MSTest in VS2010. Why accessors are not garbage collected after

  • 0

Good Day!

I’m using MSTest in VS2010. Why accessors are not garbage collected after test execution? Here is my code. It’s pretty simple.

[TestClass]
public class CheckStringsWorkTest
{
  CheckProcess checkProcess = null;
  CheckProcess_Accessor checkProcess_Accessor;

  [TestMethod]
  public void StringShaveTest()
  {
        // MessageBox.Show("Start snapshot 1");

        checkProcess = new CheckProcess();

        checkProcess_Accessor = new CheckProcess_Accessor(new PrivateObject(checkProcess));

        checkProcess.Dispose();
        checkProcess = null;
  }

  [TestCleanup()]
  public void RunAfterAllTests()
  {
     // If uncomment then GC is OK
     //checkProcess_Accessor = null; 

     try
     {
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
     }
     catch { }

     // MessageBox.Show("Start snapshot 2");
 }

As far as i understand – accessors use PrivateObject as a wrapper to hold actual object. But if I dispose and set object to null (checkProcess), cleared the reference, so the only reference to it is from accessor – why it can’t be collected? It holds actual object, not the copy of it.

  • 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-12T22:43:14+00:00Added an answer on June 12, 2026 at 10:43 pm

    You’re not nulling the checkProcess_Accessor field in your class so it, and everything it has a link to is still live and can not be collected.

    PrivateObject is obviously keeping a reference to the checkProcess it is being passed, and in turn checkProcess_Accessor must be keeping a reference to the PrivateObject. You could still get access to checkProcess via the accessor and the PrivateObject (although you might need to use reflection to do so if all the references are private) so the object can’t be collected.

    It’s a really bad idea to try and force garbage collection by the way, but I’m sure you have a valid reason for doing it.

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

Sidebar

Related Questions

Good day, Hope title is not confusing and i can be clear here. I
Good day! I've found this solution here: VS2010 Web Publish command line version of
Good day everybody! Having the following code: template<typename T, typename OutStream = std::ostream> struct
Good day everyone! I am using the T-SQL ISDATE() function with a date column
good day, I am using Joomla 1.5 and wanted to make a real estate
Good day! i have a code below: def initial(*args): for arg in args: with
Good day everyone. I have a question about making and using derived classes of
Good day, I tried parsing this query string: pkname=Paras&key=password123 with this code: printf(Content-type:text/html\n\n); printf(<html><body>);
Good day, i write script for building gcc on linux, my code is: #!/bin/bash
Good day :) I am using jQuery's animate() on both opacity and height, on

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.