Difference in using/freeing custom IProgressMon with (e.g.) PlaceHeadersAndFooters vs WriteToFile  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Difference in using/freeing custom IProgressMon with (e.g.) PlaceHeadersAndFooters vs WriteToFile

Post by zarkogajic »

Hi Support,

I have my custom implementation of IProgressMon (MyProgressMon) for when-needed usage.

When using it with PlaceHeadersAndFooters -> I have to free the used instance of MyProgressMon after the call to PlaceHeadersAndFooters has finished. I do it in Stop method implementation. All works as expected.

When using it with WriteToFile -> my instance of MyProgressMon seems to be freed by WriteToFile.

Can you confirm you deal with releasing IProgressMon differently in those two methods?

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Difference in using/freeing custom IProgressMon with (e.g.) PlaceHeadersAndFooters vs WriteToFile

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

The behavior is similar, the progress is not being released purposely.
The only difference is that the WriteToFile method stores the progress in the CComPtr<IProgressMon> variable, that automatically adds ref and releases it after the variable is being destroyed.
If you are not adding a ref count after the MyProgressMon creation, then the CComPtr adds one ref and then when the variable is destroyed it sees that there are 0 refs remaining and deletes the object.
Basically, when working with COM interfaces, you should use the AddRef/Release paradigm after the object creation and when it's being released. After you have created the object, increase it's ref count and then after you've done working with it - release it. The last release will destroy the object.


Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Difference in using/freeing custom IProgressMon with (e.g.) PlaceHeadersAndFooters vs WriteToFile  SOLVED

Post by zarkogajic »

HI Alex,

Thanks.

Just wanted to be sure those two methods deal with refs differently.

As, from what I saw, in case of PlaceHeadersAndFooters, ref count was not changed by the method.

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Difference in using/freeing custom IProgressMon with (e.g.) PlaceHeadersAndFooters vs WriteToFile

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Yup, because there is no CComPtr variable inside, that changes the Ref count.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply