void main(int argc, char* argv[])
{
STARTUPINFO si; // = { sizeof(si) };
PROCESS_INFORMATION pi;
while (true) {
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if(CreateProcess(NULL,"C:\\temp\\TestFile.exe", NULL, NULL, FALSE, 0,
NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD ExitCode;
GetExitCodeProcess(pi.hProcess, &ExitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else
{
cout << "Error CreateProcess()..." << endl;
}
}
}
I use Visual .Net and Windows 2000 Professional. With XP or XP Embedded, the
problem is still here.
Can anybody tell me what is the trouble with my code?
The code looks just fine. How do you measure those 388 bytes?
Arnaud
MVP - VC
"lugeon" <lug...@discussions.microsoft.com> wrote in message
news:433B7B08-FF3F-4CDD...@microsoft.com...
But I write here the simplest code I could wrote. My leak is still present
if I replace my constant string by a LPTSTR.
Am I the only one to get a leak with this code, or has anybody the same
trouble?
My question is: It is the code itself, the configuration of the compiler, or
something else I don't understand. I have this leak with different computer,
and I also compile with different computer.
If you run this simple code, you will see the memory for this application
that will increase with the task manager. No need to use purify or anything
else to test.
"Alexander Grigoriev" a écrit :
<<
lpCommandLine
[in, out] Pointer to a null-terminated string that specifies the
command line to execute. The maximum length of this string is 32K
characters.
Windows 2000: The maximum length of this string is MAX_PATH
characters.
The Unicode version of this function, CreateProcessW, will fail if this
parameter is a const string.
The lpCommandLine parameter can be NULL. In that case, the function
uses the string pointed to by lpApplicationName as the command line.
>>
Else:
put your string into a local TCHAR[].
Remove the std::cout function.
try it in ANSI and Unicode.
Christophe Pichaud
I added
#include <iostream>
#include <windows.h>
using namespace std;
in front of your code, and compiled with "cl -GX tmp.cpp"
Then I made a TestFile.exe which does Sleep(200) and ran the program. Task
Manager says VM size=156K. It stays that way forever...
Luc K
WAIT! I made a mistake!
VM size *does* increase, just like you said it does!
Luc K
I was able to reproduce this problem.
To my surprise, CreateProcess keeps eating memory!!!
I also found a simple workaround, but I would *really* like to get an
explanation for this!
Simply add
#include <objbase.h>
to your #include statements and at the start of your main program add one
line
HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
(or any other call that initializes the COM library).
Compile with _WIN32_DCOM defined and your leak is gone. Tested on Win2000
and WinXp.
Just don't ask me why!!!
Even simpler workaround: simply call ::SysAllocString(L"abc"); at the start
of your program...
BTW, I tried to use CreateProcessW, it has the same 'feature'!
Luc K
What does is says exactly? Where does it locate the leak?
PS : Please don't top-post
Arnaud
MVP - VC
>> By the way, you're NOT supposed to pass a constant string to
>> CreateProcess.
>
> Applies only to Unicode version.
Applies only to SOME Unicode versions.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecoreos5/html/wce50lrfCreateProcess.asp
<< BOOL CreateProcess(
<< LPCWSTR pszImageName,
<< LPCWSTR pszCmdLine,
<< [...]
<< pszCmdLine
<< [in, out] Pointer to a null-terminated string that specifies the
<< command line to execute.
I have a vague recollection of some other place too where the API requires a
pointer to constant so that the API can modify the user's constant.
Judging from what you are saying here, it looks like you just have
discovered one more bug in Windows. Apparently, if
COM library is initialized, execution takes a bit different path, so that
memory leak does not occur. This seems to be the only logical explanation
Regards
Anton Bassov
"Arnaud Debaene" <adeb...@club-internet.fr> wrote in message
news:%23vw0rYe...@TK2MSFTNGP11.phx.gbl...
Thank you very much for your help! I couldn't have found by myself....
> I was able to reproduce this problem.
> To my surprise, CreateProcess keeps eating memory!!!
On XP-SP2, I was not able to repro the problem...
Here is my code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int _tmain()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ULONG ulCount = 0;
LPTSTR szWritableCmd = new TCHAR[1024];
while(true) {
ZeroMemory(&si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi) );
LPCTSTR szCmd = _T("%SystemRoot%\\system32\\cmd.exe /c");
ExpandEnvironmentStrings(szCmd, szWritableCmd, 1024);
if(CreateProcess(NULL, szWritableCmd, NULL, NULL, FALSE, 0,
NULL, NULL, &si, &pi) != FALSE)
{
ulCount++;
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD ExitCode;
GetExitCodeProcess(pi.hProcess, &ExitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if ((ulCount % 10) == 0)
_tprintf(_T("%d\n"), ulCount);
}
else
{
_tprintf(_T("Error creating process..."));
}
}
delete [] szWritableCmd;
}
Greetings
Jochen
I can't reproduce it on XP-SP2 either.
By the way, here's the code needed to show the memory usage at runtime:
#include <psapi.h>
using namespace std;
void showMemInfo() {
PROCESS_MEMORY_COUNTERS pmc;
if ( GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)) ) {
cout << pmc.PagefileUsage << ".";
}
}
On my Win2000-SP4 this eats memory in 'steps' of 4096 or 8192 bytes...
On a Windows NT 4.0 system (tested in VMWARE), no leak either.
Luc
"David J. Craig" <Da...@yoshimuni.com> wrote in message
news:#9AH8#hUGHA...@tk2msftngp13.phx.gbl...
*ever* need to read the quoted text to get context for your reply.
message might get lost or arrive out of order... no one would
Outlook does it automatically; we don't do it because the parent
(top-to-bottom, left-to-right). After all, we only quote because
the fact that it follows the order in which people normally read
practiced in virtually all public non- microsoft.* groups, plus
read. Nevermind the fact that it's a usenet convention and is
Yes, don't bottom post. That makes everything so much harder to
David
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
There are languages that use top to bottom - right to left, such as Japanese
in normal written communications. They do use the left to right, top to
bottom, but they also use right to left in some circumstances.
"David Jones" <nc...@tadmas.com> wrote in message
news:SvbWf.3450$fS6.3068@dukeread11...
"David Jones" <nc...@tadmas.com> wrote:
> David J. Craig wrote:
>>
>> No. Please don't bottom post.
>>
>> "Arnaud Debaene" <adeb...@club-internet.fr> wrote in message
>>
>>>PS : Please don't top-post
>
> *ever* need to read the quoted text to get context for your reply.
> message might get lost or arrive out of order... no one would
> Outlook does it automatically; we don't do it because the parent
> (top-to-bottom, left-to-right). After all, we only quote because
> the fact that it follows the order in which people normally read
> practiced in virtually all public non- microsoft.* groups, plus
> read. Nevermind the fact that it's a usenet convention and is
> Yes, don't bottom post. That makes everything so much harder to
>
> David
We write online and offline mail readers since the 80s even before Microsoft
had its own. It is not a usenet convention. Before usenet, we had
corporate email systems. Top posting is more closer associated with
corporate electronic mail. The concept of "quoting", inline quoting,
bottom posting, etc was something that evolved over time.
I will venture to say that most people over 35-40, who are not experience in
the public discussion forums, whether it was online, fidonet echos,
newsgroups, etc, all use top posting replies simply because that is how it
was done with their corporate or work mail system.
You have to remember that generally most messaging is single minded, so in
most cases, top posting is fine. Sometimes you just don't want to destroy
the original content so that there is nothing taken out of content.
It is when you start to get into a "chat" like messaging where you have
multiple thoughts, concepts, long messages, maybe where a top post becomes
almost like a "disservice" to the OP sometimes because it may not cover all
the OP concepts, or maybe you don't want to either.
Just like this message with where I am covering several points, some will
top post with one or more points, others will selected quote using inline or
bottom posting.
In fact, in our old Silver Xpress Mail Reader, it has a Smart "Thought"
Quoting system where it helps you highlight and select words, sentences and
paragraphs as you read the message and allows you to quote each one
individually building it up so that the final buffer has a nicely quoted
reply messages where you can do your final edit prior to saving and sending.
This was original done for the Visually Impaired (Blind Users) as part of
our SFI (Speech Friendly Interface) system. They needed a way to HEAR each
sentence or paragraph, etc, pausing at each one so they can QUOTE it and
write a response. They loved it, and even many of the non-blind used it
too!
In any case, I've seen it all during our 25+ year history with millions of
users over the years using our mail products. I would say, at this point, I
say anyone who complains about top or bottom posting is just trying to play
"god", trying to show they know something more than the other, and in my
view, are just ignorant. However, I do believe that once you do get
involved in active participation that you use some common sense aesthetics
so that people can read your mail without straining. Typically most people
will learn for themselves just by hanging out, reading other messages nicely
quoted, etc.
--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com