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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:38:17+00:00 2026-06-13T13:38:17+00:00

I am writing an acceptance test for my managed application to ensure it is

  • 0

I am writing an acceptance test for my managed application to ensure it is not leaking memory when loading and unloading data.
Here is a sample code of what I am doing:

System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
long memoryBefore = process.PrivateMemorySize64;
// Keep creating new projects.
for (int i = 0; i < 100; i++){
   MyApplication.CreateObject();
   MyApplication.UnlaodLastCreatedObject();

   System.GC.Collect();
   System.GC.WaitForPendingFinalizers();
   System.GC.WaitForFullGCComplete();
}

To test if my process has the same memory consumption (+1MB), I do the following:

// Refresh the memory statistics
process.Refresh();
Assert.Less((decimal)process.PrivateMemorySize64,(decimal)(memoryBefore + (1024 * 1024)));

This tests seems to be not reliable at all as it randomly fails from time to time.
Anything wrong with my code above? Is there a different way to test if my process is not leaking memory?

EDIT
The failures are random, below is a screenshot of my build server output where you can clearly see the test failing from time to time.

enter image description here

Thank you.

  • 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-13T13:38:18+00:00Added an answer on June 13, 2026 at 1:38 pm

    There are two things that might be helpful for You. First, have a look on msdn for GC.WaitForFullGCComplete method

    http://msdn.microsoft.com/pl-pl/library/cc647068.aspx

    It says, that

    This method call should be preceded with a call to the WaitForFullGCApproach method to make sure that you have had a full garbage collection. Calling this method alone can produce indeterminate results.

    Second thing is, if you have any objects, that implements Finalize methods, they won’t be collected in first garbage collection (you can read a bit about freachable queue to get more overview how objects with Finalize methods work).

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

Sidebar

Related Questions

Writing my first C# application...never touched the language before and not much of a
I'm writing some acceptance tests for an application using the ActivityInstrumentationTestCase2 class. I want
I'm writing some acceptance tests for a java webapp that returns JSON objects. I
I'm writing some automated acceptance tests for a flash movie (driving the movie using
Writing Classic ASP code in JScript has a lot going for it: more humane
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing documentation in html requires some code examples. What to do with characters that
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
I'm writing a hangman code, and am having trouble with setting an error for
I'm writing an application whose purpose involves a lot of logging of different events.

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.