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

  • Home
  • SEARCH
  • 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 7630037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:59:41+00:00 2026-05-31T05:59:41+00:00

I ran different tests recently on a .net app to see how memory footprint

  • 0

I ran different tests recently on a .net app to see how memory footprint could be kept down. I came across various tips/guidelines like disposing unmanaged resources, unregistering events, using FREEZE on xaml resources etc. which all made sense. Most of the things were already taken care of , so the memory consumption remained same. I figured out however, that each new window which is never opened before in the current run, will consume some more memory and never seem to return it back after you close the window.

So I ran GC.Collect()right after the window close for debugging purpose but with no success.

In the app were a few windows with AllowsTransparency=true , so I removed the attribute and saw a big memory difference, approx.. 5MB less!, but whatever memory the window took now was still not released after the window was closed, so the problem remained the same.
Here is the sample

C#

Window w;
bool isWindowOpen = false;
private void Button_Click(object sender, RoutedEventArgs e)
{

   if (!isWindowOpen)
   {
     w = new Window();
     isWindowOpen = true;

     // turn off the following two lines to see a noteable difference.
     w.AllowsTransparency = true; 
     w.WindowStyle = WindowStyle.None;

     //Even when the transparency is set to false, the memory increased by the new 
     //Window will never be returned. Try making the window a little bit heavier by
     //adding a few buttons and combos and clicking them rapidly before closing the 
     //window.

     w.Show();
   }
   else
   { w.Close(); isWindowOpen = false; GC.Collect(); 
    //Console.WriteLine(GC.GetTotalMemory(true).ToString());
    //Console.WriteLine(GC.CollectionCount(0).ToString());
   }
 }

Can any CLR/WPF guru please explain this? Is there absolutely no way I can force GC to run immediately after I close the transparent window, freeing up all the memory it consumed? I understand GC might run later when it needs to, but after all task manager is all what clients get, and there are some maniacs also.

  • 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-31T05:59:42+00:00Added an answer on May 31, 2026 at 5:59 am

    I found that Kernal32 dll was the answer to my problem.

    [DllImport("kernel32.dll")]
    private static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
    
    SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
    

    SetProcessWorkingSetSize with -1 values will delete as many pages as it could for the process and taskmanager figures will go down drastically. I dont know however that what performance hit does it have but for my app it is perfect.

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

Sidebar

Related Questions

I ran into an issue with an IIS web app shutting down an idle
I've been teaching myself python recently an came across and example where str.endswith took
I just ran into a SQL query with about 5 different columns in the
I just ran into some code that overuse semicolons, or use semicolon for different
Ran across this line of code: FormsAuth = formsAuth ?? new FormsAuthenticationWrapper(); What do
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
I ran across this situation this afternoon, so I thought I'd ask what you
I ran across the following code in Ely Greenfield's SuperImage from his Book component
I have this app, originally written for iOS 2.x. I recently needed to add
I'm using TPTP to profile some slow running Java code an I came across

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.