System.Windows.Application class leak

I was looking for a leak in my application, when I encountered this problem. After stripping my application of all content this was the code that remained.

using namespace System;
using namespace System::Windows;

[STAThread]
int main(void)
{
    Application app;
    for(int i = 0; i < 100000000; i++)
        Window^ m = gcnew Window;
    return 0;
}

If I comment Application app; out, there is no leak, otherwise I run out of memory within a few seconds. Of course I don't need that many windows, but after adding a few hundred, which might occur, the private bytes keep increasing. I hope someone can tell me what's going on, since it is very important to me. Being careful with memory is mandatory for the application I'm building.

Answers


When I was debugging, I decided not to open the window. I did this to isolate the leak. But it seems that not closing a window (even though it has never been opened) causes a leak. In this article you can read that calling the Window.Close method fixes the problem and it did. The leak I was looking for wasn't where I thought it was.


Need Your Help

Cimg in embedded hardware

image-processing

I load a jpg into embedded system memory on an Stm32 board with assembly code via .incbin and copy the data to an alternate buffer via std::copy. The image is displayed on an attached lcd screen an...

"Facebook CDN not allowed for og:image" when sharing a Facebook post on Facebook

facebook facebook-opengraph facebook-ios-sdk meta

I have an app that pulls posts from liked Facebook groups, and allows users to share them. In order to get the correct thumbnail on the shared post, I have used the og:image meta tag when sharing. ...