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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:52:37+00:00 2026-05-11T05:52:37+00:00

Is it useful to write a standardised TDD [Test] method that would expose common

  • 0

Is it useful to write a standardised TDD [Test] method that would expose common memory issues ?

The set of tests could be easily, quickly applied to a method and would red-fail ‘classic’ .NET memory issues but would green-pass the classic solutions.

For example common memory issues could be : too much relocation by the garbage collector ; allocating too much ; too many garbage collections ( classic example prefer StringBuilder over string reallocs ); holding on to memory for too long (classic example call dispose and do not reling on finalizers ); objects inappropriately reaching g1, g2, LOH ; little leaks that add up to something significant over time, … and others.

Perhaps the code could look something like this …

[Test] public void Verify_MyMethodUnderTest_Is_Unlikely_To_Have_Common_Memory_Problem() {  //-Setup var ExpectationToleranceA = ... var ExpectationToleranceB = ... ...  //-Execute var MeasurementA = MyClassUnderTest.MyMethodUnderTest( dependancyA ) ;  var MeasurementB = MyClassUnderTest.MyMethodUnderTest( dependancyB ) ;  …  //-Verfiy Assert.That(  MeasurementA  , Is.WithinTolerance( ExpectationToleranceA  ) ) ; Assert.That(  MeasurementB  , Is.WithinTolerance( ExpectationToleranceB  ) ) ;  } 

There are other posts on memory pressure issues, but the idea here is to be able to quickly point a standard test at a method and the test would red-fail at common/classic memory pressure issues but green-pass the common solutions. A developer may then be pointed to review failing code and possibly fix the leak, change the tolerances or even remove the TDD memory pressure test.

does this idea have legs?

There is a related question here for C++ app, Memory leak detection while running unit tests, which is a similar question but not quite the same thing. Twk’s question is pointing to looking at memory after all the test have run …

My idea here is for .NET to 1) unit test each method for common memory issues 2) fail the classic memory issues 3) pass the classic fixes to classic common memory issues 4) be able to quickly throw a quick standard test at a function to see whether it exhibits classic symptoms 5) be able to upgrade the Standard TDD .Net Memory Pressure Test applied in the unit test. This implies a refactor of the above code so that upgrades to the standard test will change upgrade the memory tests applied throughout the Nunit test suite for a project.

(p.s. I know there is no Is.WithinTolerance call but I was just demonstrating an idea. ) cheers …

  • 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. 2026-05-11T05:52:37+00:00Added an answer on May 11, 2026 at 5:52 am

    Good unit tests should be pointed on small pieces of code. Ideally they should be repeatable, which will be not the case, when the garbage collector is involved.

    Nevertheless you can use unit testing framework facilities for doing non-unit tests (functional tests, regression tests, stress tests, …). But you need to be aware, that you are not doing real unit tests. So don’t use them in some automatic builds and don’t force other developers to include such tests in their commit tests. Real unit tests may not suffer from non-unit tests!

    If you want to do something like this, consider invoking the GC.Collect() method before and after the operation you want to test. Make several calls in a row to sense a growth in memory consumption more easily. Consider adding such tests in a separate overnight build (separate from real unit tests), because that may be time consuming. Invoke the tests on a separate machine, where you have full control (a open browser with some flash animation or a virus scanner during the tests may mess up your results). Store figures for the memory consumption somewhere for later review. This will make you aware of slowly increasing memory consumption during long development cycles.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not familiar with writing services in .NET, but in… May 12, 2026 at 12:29 am
  • Editorial Team
    Editorial Team added an answer Assuming safe code with no COM components, P/Invoke, etc. there… May 12, 2026 at 12:29 am
  • Editorial Team
    Editorial Team added an answer Generally the schema can be open to change in the… May 12, 2026 at 12:29 am

Related Questions

I am trying to write a cross-platform python program that would run in the
I have a project that is deployed to production as a windows service. However
I'm doing a project at uni and would like to create zip files which
I need to call a web service written in .NET from Java. The web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.