Print Page | Close Window

GUI Resource Problem

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=6428
Printed Date: 29 May 2024 at 1:00am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: GUI Resource Problem
Posted By: Tsenoh
Subject: GUI Resource Problem
Date Posted: 15 February 2007 at 10:08am
Hi!
 
In my application I am using Dialogs with ribbons. Dialogs are often opened and closed. Whenever I close a dialog I don't destroy it. I just destroy all elements in it. I use RemoveAllTabs to destroy Ribbon elements. This way I don't have to initialise dialog every time it is opened. I just recreate the child controls.
 
Problem occures when I open and close same dialog multiple times (10-15 times). Suddenly GUI goes crazy. No button can be drawn, all windows use default font, etc. It seems that GUI handles are not released when a control is destroyed.
 
Has anyone had similar problem?
 
Any ideas how I can solve this problem?
 
Thanks!
 
Bojan Hrnkas



Replies:
Posted By: Oleg
Date Posted: 15 February 2007 at 11:11am
Hi
May be you call InitCommandBars each time you show dialog or something.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Tsenoh
Date Posted: 19 February 2007 at 11:12am
I did indeed. However that was not the problem. I am using SetCustomIcon() for my buttons. I figured out that there is a memory leak in that function, so I have around 700 leaks per dialog start. If those leaks are all icon handles, or any other gui handles, I understand the problem.
 
Is there something I have to do to destroy resources created by SetCustomIcon()?


Posted By: kstowell
Date Posted: 19 February 2007 at 12:37pm
HI Tsenoh,
 
You can try using CXTPImageManagerIconHandle instead of HICON. This will automatically clean up your icon resources when the object is destroyed.
 
Instead of:
HICON hIcon =

Use:
CXTPImageManagerIconHandle hIcon =

Hope this helps.
 
Regards,
Kirk Stowell


Posted By: Oleg
Date Posted: 20 February 2007 at 2:03am
Hello,
SetCustomIcon each time reserves new Id for Icon. I very recommend yo use SetIcons method instead.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Tsenoh
Date Posted: 20 February 2007 at 9:57am
If I understood corectly. When using SetIcons, icons are mapped through controll message id. We use our own message system, and the ID's are only unique within a dialog. Not within the application. That is why I use SetCustomIcon.


Posted By: Tsenoh
Date Posted: 28 September 2007 at 11:07am
Hi!
I've now checked my application using following tool: http://www.download.com/DPusLight/3000-2218_4-10424495.html?tag=pdp_prod - http://www.download.com/DPusLight/3000-2218_4-10424495.html?tag=pdp_prod
 
It shows that resources created by CreateCompatibleBitmap are not freed untill I destroy the dialog. I am never calling CreateCompatibleBitmap myself for theese icons (in the tool there is an image of the resources in question), so it has to be somewhere in the XTP code.
However, those resources are not created each time I show the dialog, so it is not really a leak. It seems to me that is some kind of cache for the bitmaps that are to be drawn on the ribbon.
Is there a possibility to disable it? Since my application has hundreds of dialogs that are dynamicaly created, the GDI Resource count pretty soon reaches the magic number 10.000.
 
Any ideas?
 
Thanks!


Posted By: Tsenoh
Date Posted: 28 September 2007 at 1:48pm

Hi, again!

Please consider following code:


void CXTPRibbonTheme::FillGroupPopupToolBar(CDC* pDC, CXTPRibbonGroup* pGroup, CXTPCommandBar* pCommandBar)
{
 pDC->SetBkMode(TRANSPARENT);

 CXTPClientRect rcRibbon(pCommandBar);

 pDC->FillSolidRect(rcRibbon, RGB(191, 219, 255));

 rcRibbon.InflateRect(3, 3);
 XTPRibbonTabContextColor tabColor = pGroup->GetParentTab()->GetContextColor();

 if (tabColor != xtpRibbonTabContextColorNone)
 {
  CXTPOffice2007Image* pImage = LoadImage(FormatName(_T("CONTEXTTAB%sCLIENT"), GetColorName(tabColor)));
  if (pImage) pImage->DrawImage(pDC, rcRibbon, pImage->GetSource(0, 1), CRect(8, 8, 8, 8));
 }
 else
 {
  CXTPOffice2007Image* pImage = LoadImage(FormatName(_T("RIBBONGROUPS")));
  if (pImage) pImage->DrawImage(pDC, rcRibbon, pImage->GetSource(0, 1), CRect(8, 8, 8, 8));
 }
}

pImage is never deleted. Is that a leak, or am I missing something and that objects are destroyed elsewhere? Thanks!


Posted By: Oleg
Date Posted: 29 September 2007 at 1:54am
Hi,
 
Images are stored in CXTPOffice2007Images class and will be destroyed after skin changed or in destructor of this class.
 
Better attach code you use in your dialog, I will check where you forget to free resources.
Our library doesn't have memory leaks.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Tsenoh
Date Posted: 01 October 2007 at 5:47am
I see. I know the problem now. We are not destroying the Dialog Object, so the CXTPOffice2007Images isn't destroyed as well. Is there a possibility to empty that map and destroy it's elements other than destroying the Object itself?
Thanks!


Posted By: Oleg
Date Posted: 01 October 2007 at 5:59am
Hi,
Call
 
((CXTPOffice2007Theme*)pCommandBars->GetPaintManager())->GetImages()->RemoveAll();


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Tsenoh
Date Posted: 01 October 2007 at 10:04am
Ok, that solved a part of the problem.
Thanks a lot!
Other leaks are probably in our code.
Some other thing, I see that Fonts are stored with each CXTPRibbonBar instance. Probably again in the Theme. They don't take up much space, but it would be nice if I could destroy them too.


Posted By: Oleg
Date Posted: 01 October 2007 at 1:40pm
HI,
 
If you use CommandBars/PaintManager only with this dialog, you can free all PaintManager:
 
CXTPPaintManager::Done()


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net