Print Page | Close Window

CXTPObservable leaks during XTPShutdown

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=24539
Printed Date: 22 April 2025 at 11:28am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPObservable leaks during XTPShutdown
Posted By: ganzeiss
Subject: CXTPObservable leaks during XTPShutdown
Date Posted: 19 January 2025 at 9:19pm
Hi, I am currently migrating from CodeJock 19.3 to CodeJock 24.0 and found that this issue is occurring to me. I use the static function CXTPPaintManager::SetTheme(xtpThemeVisualStudio2015) to set the theme for the paint manager. 

However, when I call CXTPWinApp::ExitInstance(), and as the app starts to close, when XTPShutdown() is called during ~XTPApplication(), I get an assertion error during:
template<class Owner, class Observer>
AFX_INLINE CXTPObservable<Owner, Observer>::~CXTPObservable()
{
    ASSERT("All observers must be unsubscribed before destruction" && 0 == m_Observers.GetSize());
}

I can use CXTPPaintManager::SetTheme(xtpThemeOffice2000) before calling CXTPWinApp::ExitInstance(), this error doesn't occur. I wanted to ask if there is a more elegant solution, or if this workaround is the only solution at the moment.



Replies:
Posted By: agontarenko
Date Posted: 04 February 2025 at 9:05am
Hello,

It seems that quite a bit of time has passed between these revisions.
We have modified application themes, now it uses XTPPaintManager()->SetTheme(nTheme); call instead of CXTPPaintManager::SetTheme(), maybe this is the problem.

Please see how this is implemented in CommandBarControls.

Regards,
Artem Gonarenko


Posted By: agontarenko
Date Posted: 04 February 2025 at 9:11am
Can you provide sample with this problem?

Regards,
Artem Gonarenko


Posted By: ganzeiss
Date Posted: 06 February 2025 at 5:45am
Hi agontarenko,

I tried the method you mentioned previously in replacing CXTPPaintManager::SetTheme() call with XTPPaintManager()->SetTheme(nTheme), but the issue still persisted. It's very strange, since we did not have this issue in 19.3.0, but it showed up suddenly in 24.0.0.

I have been trying to recreate the issue with Samples from the CodeJock toolkit, but I am unable to recreate the issue through the samples. Trying to separate the problematic portion from the affected software is also quite difficult.

Other than the workaround of setting CXTPPaintManager::SetTheme(xtpThemeOffice2000), I found another where I run the following before executing CXTPWinApp::ExitInstance() :

auto RefCount = CXTPPaintManager::GetInstanceAddRef();
  DWORD nOldRefCount = RefCount->InternalRelease();
  while (1 < RefCount->InternalRelease())
    ;

Which I still feel is a bit of weird workaround. I will try to reply with a Sample of the issue as soon as I can, but at the moment, this is the only information I can really scrounge up.

Note: I am not sure if this is relevant, but to make CodeJock 24.0.0 work with our code, we had to remove the following macro _XTP_EXCLUDE_MARKUP from our code (although doing this for the software in 19.3.0 did not yield the same issue)


Posted By: agontarenko
Date Posted: 25 February 2025 at 7:32am
Hello,

How I written early, between 19.3 and 24.1 many changes were.
Was unified use of themes, because our samples used themes code differently (part of our samples already changed with new code based on wizard).
Codejock application wizard has been added in Visual Studio.
So ideally you need to create with our wizard application like as you have. And modify you sample like wizard sample.

Pay attention to CXTPWinApp and ExitInstance() usage.
Example:
int CCommandBarControlsApp::ExitInstance()
{
    // TODO: handle additional resources you may have added
    AfxOleTerm(FALSE);

    return CXTPWinApp::ExitInstance();/// <<--
}

Regards,
Artem Gonarenko



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