I'm currently writing a replacement shell and am suffering from quite dire memory leaks, when running, every time I roll my mouse over the taskbar icon a new window scrolls out revealing the window's caption and then on WM_MOUSELEAVE the window closes again. somehow this process also increases my program's private working set by 40K (using SysInternals' Process Explorer) Any help would be appreciated.
Extract from TaskbarItem.cpp : - LRESULT CALLBACK TaskbarItem::LocalProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
-
switch(msg){
-
case WM_MOUSEMOVE:{
-
if(this->caption==(TaskExpander*)NULL)
-
this->caption=new TaskExpander(&(*this));
-
else
-
this->caption->Reopen();
-
}break;
-
case WM_MOVED:
-
if(caption!=(TaskExpander*)NULL){
-
SendMessage(caption->GetDispHWnd(),WM_MOVED,0,0);
-
}
-
break;
-
default:return DefWindowProc(hWnd,msg,wParam,lParam);
-
}
-
return 0L;
-
}
Extract from TaskExpander.cp p: -
void TaskExpander::Reopen (){
-
if((state & _O)==0){
-
KillTimer(dWnd,IDT_TIMER_CLOSE);
-
KillTimer(dWnd,IDT_TIMER_TIMEOUT);
-
state=OPENING;
-
SetTimer(dWnd,IDT_TIMER_OPEN,ANI_TIME,0);
-
ShowWindow(dWnd,SW_SHOW);
-
}
-
}
-
LRESULT CALLBACK TaskExpander::LocalProc (HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
-
LPPAINTSTRUCT ps=new PAINTSTRUCT;
-
HDC hdc;
-
HFONT hFont;
-
hFont=global::font::basic;
-
switch(msg){
-
case WM_MOVED:{
-
LPRECT r=new RECT;
-
LPRECT s=new RECT;
-
GetWindowRect(pTbi->GetDispHWnd(),r);
-
GetWindowRect(hWnd,s);
-
position.x=r->right;
-
position.y=r->top-1;
-
MoveWindow(hWnd,position.x-(s->right-s->left),position.y,(r->right-r->left),r->bottom-r->top,true);
-
InvalidateRgn(hWnd,NULL,TRUE);
-
}break;
-
case WM_PAINT:{
-
hdc=BeginPaint(hWnd,ps);
-
SetBkColor(hdc,0x00000000);
-
SelectObject(hdc,hFont);
-
SetTextColor(hdc,0x00FFFFFF);
-
size_t psz;
-
LPRECT r=new RECT;
-
GetWindowRect(hWnd,r);
-
HICON icon=pTbi->GetIcon();
-
StringCchLength(pTbi->GetTitle(),MAX_LOADSTRING,&psz);
-
TextOut(hdc,2*ICON_GAP+ICON_SIZE,ICON_GAP/2,pTbi->GetTitle(),psz);
-
DrawIconEx(hdc,ICON_GAP,0,icon,ICON_SIZE,ICON_SIZE,0,NULL,DI_NORMAL);
-
EndPaint(hWnd,ps);
-
delete r;
-
}break;
-
case WM_TIMER:
-
switch(wParam){
-
case IDT_TIMER_OPEN:{
-
state=OPENING;
-
hdc=GetDC(hWnd);
-
LPRECT r=new RECT;
-
size_t psz;
-
SIZE size;
-
SelectObject(hdc,hFont);
-
StringCchLength(pTbi->GetTitle(),MAX_LOADSTRING,&psz);
-
GetTextExtentPoint32(hdc,pTbi->GetTitle(),*&psz,&size);
-
GetWindowRect(hWnd,r);
-
if((size.cx+(2*ICON_GAP)+ICON_SIZE)-(r->right-r->left)>ANI_STEP)
-
MoveWindow(hWnd,position.x-(r->right-r->left)-ANI_STEP,position.y,(r->right-r->left)+ANI_STEP,r->bottom-r->top,true);
-
else{
-
MoveWindow(hWnd,position.x-(size.cx+(2*ICON_GAP)+ICON_SIZE),position.y,(size.cx+(2*ICON_GAP)+ICON_SIZE),r->bottom-r->top,true);
-
KillTimer(hWnd,IDT_TIMER_OPEN);
-
SetTimer(hWnd,IDT_TIMER_TIMEOUT,10000,(TIMERPROC)NULL);
-
state=OPEN;
-
}
-
delete r;
-
}break;
-
case IDT_TIMER_CLOSE:{
-
state=CLOSING;
-
KillTimer(hWnd,IDT_TIMER_TIMEOUT);
-
LPRECT r=new RECT;
-
GetWindowRect(hWnd,r);
-
MoveWindow(hWnd,position.x-(r->right-r->left)+ANI_STEP,position.y,(r->right-r->left)-ANI_STEP,r->bottom-r->top,true);
-
if(r->right-r->left <= ICON_SIZE+ANI_STEP){
-
KillTimer(hWnd,IDT_TIMER_CLOSE);
-
state=READY;
-
ShowWindow(hWnd,SW_HIDE);
-
}
-
delete r;
-
}break;
-
case IDT_TIMER_TIMEOUT:{
-
KillTimer(hWnd,IDT_TIMER_OPEN);
-
this->state=CLOSING;
-
SetTimer(hWnd,IDT_TIMER_CLOSE,ANI_TIME,(TIMERPROC)NULL);
-
}break;
-
}break;
-
case WM_INIT:
-
ShowWindow(dWnd,SW_SHOW);
-
SetTimer(hWnd,IDT_TIMER_OPEN,ANI_TIME,(TIMERPROC)NULL);break;
-
state=OPENING;
-
break;
-
case WM_MOUSEMOVE:
-
if(state==CLOSING){
-
KillTimer(hWnd,IDT_TIMER_CLOSE);
-
SetTimer(hWnd,IDT_TIMER_OPEN,ANI_TIME,(TIMERPROC)NULL);
-
}
-
if(!tracking){
-
TRACKMOUSEEVENT tme;
-
tme.cbSize=sizeof(tme);
-
tme.dwFlags=TME_LEAVE;
-
tme.hwndTrack=hWnd;
-
TrackMouseEvent(&tme);
-
tracking=true;
-
}
-
break;
-
case WM_MOUSELEAVE:
-
KillTimer(hWnd,IDT_TIMER_OPEN);
-
KillTimer(hWnd,IDT_TIMER_TIMEOUT);
-
SetTimer(hWnd,IDT_TIMER_CLOSE,ANI_TIME,0);
-
state=CLOSING;
-
tracking=false;
-
break;
-
case WM_LBUTTONDOWN:
-
SetForegroundWindow(pTbi->GetHWnd());
-
SetActiveWindow(pTbi->GetHWnd());
-
break;
-
default:delete ps,hdc,hFont;return DefWindowProc(hWnd,msg,wParam,lParam);
-
}
-
return 0L;
-
}
5 2805 Banfa 9,065
Recognized Expert Moderator Expert
I see the code allocating TaskExpanders
this->caption=new TaskExpander(&( *this));
but never deleting them and I see the code deleting pointers
default:delete ps,hdc,hFont;re turn DefWindowProc(h Wnd,msg,wParam, lParam);
that have not had memory allocated to them while most of the time it doesn't delete
LPPAINTSTRUCT ps=new PAINTSTRUCT;
allocated PAINTSTRUCTs
Thank you for your response. @Banfa
They would be deleted in the destructor for the TaakbarItem, however this should only cause the memory to go up on the first call surely? memory goes up every time the expander reopens.
adding the "delete ps;" in the relevant places has roughly halved the memory leaking. I managed to find the main cause to be the GetDC() on line 45, adding a corresponding releaseDC has solved the problem.
Thank you for your help.
You are creating new RECT variables in several places. How are those cleaned up?
@weaknessforcats
Those are now all being deleted after use.
Thank you for your help.
This aspect of the program no longer leaks, the rest of the program has the memory management of a sieve but i should be able to sort that out. Thank you.
Banfa 9,065
Recognized Expert Moderator Expert
I don't know if this is code you inherited or wrote but personally whenever I allocate memory from the heap using new I always put in the corresponding delete immediately before filling in any other code.
You may also want to consider using the handle template Sign in to post your reply or Sign up for a free account.
Similar topics |
by: cyberstrike |
last post by:
okay, I have a wierd problem. first of all, when my app loads, it uses a lot
of memory. Most of which goes away if I minimize and reopen the application.
Second problem is that I have a datagrid on the application and as long as a
mouse is moving over the datagrid, it keeps accumulating memory and never
releases it. I don't have any events that should be causing this. Also, if I
move the mouse over other parts of the form, not the datagrid,...
|
by: ranjeet.gupta |
last post by:
Dear All
Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
Juts Theoritical Assumtion below:
|
by: Chris Oates |
last post by:
I'm using interop to bring in user32.dll and gdi32.dll, and I'm finding that
I appear to have some kind of memory leak in the CLR. use of
GC.GetTotalMemory() shows a lot of motion, but it does not continually grow,
leaving me to think that it's a problem with my interop calls.
I have a timer set up which calls the following function 20 times per
second. It finds the color of the pixel under the mouse cursor. The real
version does more...
|
by: Perry |
last post by:
Hi,
I have a problem with the memory consumption of the AppDomain.Load and unload.
For example, when i run this code, the memory usage is increasing.
MessageBox.Show(string.Format("Before: {0}",GC.GetTotalMemory(true)));
for (int i = 0; i < 100; i++)
{
AppDomain appDom = AppDomain.CreateDomain(string.Format("SubDom_{0}",i));
|
by: Anton |
last post by:
{Willy Skjveland} Hi, how can I trace a Memory leak in aspnet_wp.exe?
{Rheena} One moment please while I search it for you. It may take me a few
moments
{Willy Skjveland} I need to find out which application and which dll and
asmx page that cause the problem.
{Rheena} May I know what operating system you are using?
| |
by: Adrian |
last post by:
Hi
I have a JS program that runs localy (under IE6 only) on a PC but it has
a memory leak (probably the known MS one!)
What applications are there that I could use to look at the memory usage of
each object within my JS app to help locate my problem?
Thanks
|
by: eduard.antonyan |
last post by:
All I'm doing is going through the webpage and analyzing the data,
here's the outline of the code:
in OnDocumentComplete(LPCTSTR lpszURL)
{
IDispatch *pDispatch = GetHtmlDocument();
IHTMLDocument2 *pDoc;
IHTMLElement *pBody;
BSTR str;
|
by: Peter |
last post by:
I am using VS2008.
I have a Windows Service application which creates Crystal Reports. This is
a multi theaded application which can run several reports at one time.
My problem - there is a memory leak someplace. I can not detect the memory
leak by running several reports by hand, but when I run tha app as a
servrice and process few hundred reports there is significant memory leak.
The application can consume over 1GB of memory where it...
|
by: Daniel Orner |
last post by:
Hi all,
I've been trying to pin down a memory leak in IE6 for several WEEKS
now. I've done my share of googling etc., and know all about common
leaks like circular references and closures, but have found nothing like
this.
This app is designed to run in a kiosk environment, so it has
things like a persistent frame which holds data as well as the visible
frame (actually an iframe). After 1,000 page transitions our app is up
by almost...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |