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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:18:07+00:00 2026-05-16T08:18:07+00:00

I have experienced a strange problem in windows vista and above. When I use

  • 0

I have experienced a strange problem in windows vista and above. When I use the IFileOpenDialog with a large stack, the amount of memory remaining after showing the dialog drops by about a gigabyte.

#include <windows.h>
#include <Shobjidl.h>
#include <iostream>

void memGrab(char *);
int main(int argc, char **argv){
  char Message[128];
  CoInitialize(NULL);
  if(argc > 1){
    wsprintf(Message, "Starting Memory Test: %c", argv[1][0]);
    std::cout << Message << "\n";
    if(argv[1][0] == 'b')
      memGrab("before");
    TCHAR *fileName = (TCHAR *)malloc(sizeof(TCHAR) * 1024);

      IFileOpenDialog *pfd;
    int index = 0;
    int len = 0;
    int i = 0;

    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_PPV_ARGS(&pfd));

    if(SUCCEEDED(hr)){
      pfd->Show(NULL);
    }
    pfd->Release();
    if(argv[1][0] == 'a')
      memGrab("After");
  }
  CoUninitialize();
}

void memGrab(char *text){
  for(int i = 0; i < 400000; i++){
    if(!malloc(10240)){
      char Message[128];
      wsprintf(Message, "Memory Gone %s: %d K", text, i * 10);
      std::cout << Message << "\n";
      exit(0);
    }
  }
}

When I compile this program without setting a stack size (cl testMem.cpp Shell32.lib Ole32.lib user32.lib). I get the following result:

C:\RWSource>testMem.exe b
Starting Memory Test: b
Memory Gone before: 1984040 K

C:\RWSource>testMem.exe a
Starting Memory Test: a
Memory Gone After: 1875640 K

However, when I compile it with setting the stack size (cl testMem.cpp Shell32.lib Ole32.lib user32.lib /F100000000). I loose a large amount of allocatable memory.

C:\RWSource>testMem.exe b
Starting Memory Test: b
Memory Gone before: 1795370 K

C:\RWSource>testMem.exe a
Starting Memory Test: a
Memory Gone After: 463840 K

Update 1:

I checked the memory with VMMap (thank you TheUndeadFish) and when I open the dialog, there are multiple threads started that all have about 100MB. Is there any way to make the main thread have a large stack while not giving the child threads 100MB each?

Update 2:

I came back to this problem again after a few months. I moved the main code to another function and started it as a thread with the specified stack size. No need for the stack size on compile.

int main(){
  CreateThread(NULL, 100000000, analyze, NULL, 0, NULL);
  // Wait for analyze thread. 
}

int analyze(int ignore){
  // Do stuff
}
  • 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-16T08:18:07+00:00Added an answer on May 16, 2026 at 8:18 am

    I don’t know exactly what’s going on in your scenario. But I have seen the File Open Dialog cause other memory trouble before.

    When that dialog is invoked, a lot of things may get loaded into your process. In particular, shell extensions that appear in Windows Explorer also get loaded in with the File Open Dialog. That’s how you’re able to right click on a file in that dialog and get all those non-standard goodies. However, this means that the dlls that underlie those extensions are getting loaded into your process.

    From experience, I have seen that some of those dlls do not get unloaded once the File Open Dialog is closed. Instead they stay present, taking up some of the address space of your process. (Maybe this is some kind of bug on the part of those dlls, or maybe it’s some kind of “optimization” to keep them loaded in case the File Open Dialog is used again.)

    The consequence of this that I dealt with was that it affected the success of a single 1GB memory allocation. Before opening the dialog there was a large stretch of address space available and a 1GB allocation could succeed. However after opening the dialog, a couple of the shell extension dlls landed right in the middle of the available address space and divided it into chunks smaller than 1GB, thus causing the allocation to fail.

    I know this anecdote doesn’t relate directly to what you’re doing, since you’re allocating many small amounts instead of one large amount. (And in my scenario it wasn’t malloc being used. I think it was something like VirtualAlloc or such.) But I would guess something roughly similar may be happening.

    The File Open Dialog may be loading something into your process that somehow inserts a barrier into the space that malloc would normally use. But somehow this only happens when you’re using that large stack size because I guess that extra 99MB of space reserved for the stack is somehow rearranging the rest of the address space to be susceptible to this problem.

    When I was investigating my own issue, I used VMMap to take snapshots of my process’s address space at various points to figure out what was happening. You might have some luck doing that. Just note that it looks at the address space like the operating system sees it, not really like you see it from inside the context a specific language like C++. So it’s not necessarily easy to figure out what particular part of memory is being used by malloc or any other allocation mechanism.

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

Sidebar

Related Questions

I have a pretty strange HTML problem I have never experienced before. I have
I've experienced rather strange behavior of JSTL forEach tag. I have some bean called
I have experienced strange functionality of subversion. We are using latest 1.6 Svn server
I have a very strange problem with the Delphi 2006 IDE. If the IDE
I have a strange problem with sinatra... In my app the login form is
I have a strange problem in my ASP.Net 3.5 application. When multiple users try
I have the following strange problem in Oracle (Please keep in mind that I
Very strange, not sure if others have experienced this... Exporting with Flash CS5.5 to
I have experienced some strange behavior of Objective-C++. I have an Objective-C++ class, and
I have this very strange problem on a big flex app where it would

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.