473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory Leak (40K per mouse over)

11 New Member
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 :

Expand|Select|Wrap|Line Numbers
  1. LRESULT CALLBACK            TaskbarItem::LocalProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
  2.     switch(msg){
  3.         case WM_MOUSEMOVE:{
  4.             if(this->caption==(TaskExpander*)NULL)
  5.                 this->caption=new TaskExpander(&(*this));
  6.             else
  7.                 this->caption->Reopen();
  8.         }break;
  9.         case WM_MOVED:
  10.             if(caption!=(TaskExpander*)NULL){
  11.                 SendMessage(caption->GetDispHWnd(),WM_MOVED,0,0);
  12.             }
  13.             break;
  14.         default:return DefWindowProc(hWnd,msg,wParam,lParam);
  15.     }
  16.     return 0L;
  17. }
Extract from TaskExpander.cp p:
Expand|Select|Wrap|Line Numbers
  1. void                                TaskExpander::Reopen        (){
  2.     if((state & _O)==0){
  3.         KillTimer(dWnd,IDT_TIMER_CLOSE);
  4.         KillTimer(dWnd,IDT_TIMER_TIMEOUT);
  5.         state=OPENING;
  6.         SetTimer(dWnd,IDT_TIMER_OPEN,ANI_TIME,0);
  7.         ShowWindow(dWnd,SW_SHOW);
  8.     }
  9. }
  10. LRESULT CALLBACK                    TaskExpander::LocalProc        (HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
  11.     LPPAINTSTRUCT ps=new PAINTSTRUCT;
  12.     HDC hdc;
  13.     HFONT hFont;
  14.     hFont=global::font::basic;
  15.     switch(msg){        
  16.         case WM_MOVED:{
  17.             LPRECT r=new RECT;
  18.             LPRECT s=new RECT;
  19.             GetWindowRect(pTbi->GetDispHWnd(),r);
  20.             GetWindowRect(hWnd,s);
  21.             position.x=r->right;
  22.             position.y=r->top-1;
  23.             MoveWindow(hWnd,position.x-(s->right-s->left),position.y,(r->right-r->left),r->bottom-r->top,true);
  24.             InvalidateRgn(hWnd,NULL,TRUE);
  25.         }break;
  26.         case WM_PAINT:{
  27.             hdc=BeginPaint(hWnd,ps);
  28.             SetBkColor(hdc,0x00000000);
  29.             SelectObject(hdc,hFont);
  30.             SetTextColor(hdc,0x00FFFFFF);
  31.             size_t psz;
  32.             LPRECT r=new RECT;
  33.             GetWindowRect(hWnd,r);
  34.             HICON icon=pTbi->GetIcon();
  35.             StringCchLength(pTbi->GetTitle(),MAX_LOADSTRING,&psz);
  36.             TextOut(hdc,2*ICON_GAP+ICON_SIZE,ICON_GAP/2,pTbi->GetTitle(),psz);
  37.             DrawIconEx(hdc,ICON_GAP,0,icon,ICON_SIZE,ICON_SIZE,0,NULL,DI_NORMAL);
  38.             EndPaint(hWnd,ps);
  39.             delete r;
  40.             }break;
  41.         case WM_TIMER:
  42.             switch(wParam){
  43.                 case IDT_TIMER_OPEN:{
  44.                     state=OPENING;
  45.                     hdc=GetDC(hWnd);
  46.                     LPRECT r=new RECT;
  47.                     size_t psz;
  48.                     SIZE size;
  49.                     SelectObject(hdc,hFont);
  50.                     StringCchLength(pTbi->GetTitle(),MAX_LOADSTRING,&psz);
  51.                     GetTextExtentPoint32(hdc,pTbi->GetTitle(),*&psz,&size);
  52.                     GetWindowRect(hWnd,r);
  53.                     if((size.cx+(2*ICON_GAP)+ICON_SIZE)-(r->right-r->left)>ANI_STEP)
  54.                         MoveWindow(hWnd,position.x-(r->right-r->left)-ANI_STEP,position.y,(r->right-r->left)+ANI_STEP,r->bottom-r->top,true);
  55.                     else{
  56.                         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);
  57.                         KillTimer(hWnd,IDT_TIMER_OPEN);
  58.                         SetTimer(hWnd,IDT_TIMER_TIMEOUT,10000,(TIMERPROC)NULL);
  59.                         state=OPEN;
  60.                     }
  61.                     delete r;
  62.                 }break;
  63.                 case IDT_TIMER_CLOSE:{
  64.                     state=CLOSING;
  65.                     KillTimer(hWnd,IDT_TIMER_TIMEOUT);
  66.                     LPRECT r=new RECT;
  67.                     GetWindowRect(hWnd,r);
  68.                     MoveWindow(hWnd,position.x-(r->right-r->left)+ANI_STEP,position.y,(r->right-r->left)-ANI_STEP,r->bottom-r->top,true);
  69.                     if(r->right-r->left <= ICON_SIZE+ANI_STEP){
  70.                         KillTimer(hWnd,IDT_TIMER_CLOSE);
  71.                         state=READY;
  72.                         ShowWindow(hWnd,SW_HIDE);
  73.                     }
  74.                     delete r;
  75.                 }break;
  76.                 case IDT_TIMER_TIMEOUT:{
  77.                     KillTimer(hWnd,IDT_TIMER_OPEN);
  78.                     this->state=CLOSING;
  79.                     SetTimer(hWnd,IDT_TIMER_CLOSE,ANI_TIME,(TIMERPROC)NULL);
  80.                 }break;
  81.             }break;
  82.         case WM_INIT:
  83.             ShowWindow(dWnd,SW_SHOW);
  84.             SetTimer(hWnd,IDT_TIMER_OPEN,ANI_TIME,(TIMERPROC)NULL);break;
  85.             state=OPENING;
  86.             break;
  87.         case WM_MOUSEMOVE:
  88.             if(state==CLOSING){
  89.                 KillTimer(hWnd,IDT_TIMER_CLOSE);
  90.                 SetTimer(hWnd,IDT_TIMER_OPEN,ANI_TIME,(TIMERPROC)NULL);
  91.             }
  92.             if(!tracking){
  93.                 TRACKMOUSEEVENT tme;
  94.                 tme.cbSize=sizeof(tme);
  95.                 tme.dwFlags=TME_LEAVE;
  96.                 tme.hwndTrack=hWnd;
  97.                 TrackMouseEvent(&tme);
  98.                 tracking=true;
  99.             }
  100.             break;
  101.         case WM_MOUSELEAVE:
  102.             KillTimer(hWnd,IDT_TIMER_OPEN);
  103.             KillTimer(hWnd,IDT_TIMER_TIMEOUT);
  104.             SetTimer(hWnd,IDT_TIMER_CLOSE,ANI_TIME,0);
  105.             state=CLOSING;
  106.             tracking=false;
  107.             break;
  108.         case WM_LBUTTONDOWN:
  109.             SetForegroundWindow(pTbi->GetHWnd());
  110.             SetActiveWindow(pTbi->GetHWnd());
  111.             break;
  112.         default:delete ps,hdc,hFont;return DefWindowProc(hWnd,msg,wParam,lParam);
  113.     }
  114.     return 0L;
  115. }
Dec 1 '08 #1
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
Dec 1 '08 #2
RomeoPapacy
11 New Member
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.
Dec 1 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are creating new RECT variables in several places. How are those cleaned up?
Dec 1 '08 #4
RomeoPapacy
11 New Member
@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.
Dec 1 '08 #5
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
Dec 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
487
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,...
8
3417
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:
3
1964
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...
1
2754
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));
9
425
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?
8
8559
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
6
2442
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;
22
9370
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...
18
2151
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...
0
9706
marktang
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...
0
10077
tracyyun
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...
1
7620
isladogs
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...
0
6853
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();...
0
5522
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
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
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.