Recent

Author Topic: unit init, finalize and init_implicit, finalize_implicit.  (Read 1238 times)

JernejL

  • Full Member
  • ***
  • Posts: 111
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #15 on: January 14, 2026, 12:46:03 pm »
Adding to this thread:
 
See attachment.
 
If finalize_implicit is only called when unit is "finalized" - implying that program has to terminate, why do i see these TDC_GAME_$$_finalize_implicit$ calls in profiling (application was not terminated to call any unit finalization)?
 
Additionally, TDC_GAME unit does not even have a initialization or finalization section at all.. why is TDC_GAME_$$_finalize_implicit$ then even in debug symbols, and why does it show up in profiling as being called? 
 
« Last Edit: January 14, 2026, 12:54:48 pm by JernejL »

Zvoni

  • Hero Member
  • *****
  • Posts: 3242
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #16 on: January 14, 2026, 01:06:11 pm »

Additionally, TDC_GAME unit does not even have a initialization or finalization section at all.. why is TDC_GAME_$$_finalize_implicit$ then even in debug symbols, and why does it show up in profiling as being called?
As Thaddy wrote: Does the TDC_GAME-Unit depend on a unit which HAS explicit Finalization?
Or as PascalDragon wrote: Does this TDC_Game-unit has a, for example, Typed AnsiString-Constant?
« Last Edit: January 14, 2026, 01:08:25 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JernejL

  • Full Member
  • ***
  • Posts: 111
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #17 on: January 14, 2026, 01:51:19 pm »
I try to avoid ansistring as much as possible, and nearly all strings in my code are unicodestrings, with some widestrings where winapi is needed.
 
Still, that does not explain why finalization would even be called when program was never terminated.
 

Zvoni

  • Hero Member
  • *****
  • Posts: 3242
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #18 on: January 14, 2026, 02:43:41 pm »
I try to avoid ansistring as much as possible, and nearly all strings in my code are unicodestrings, with some widestrings where winapi is needed.
 
Still, that does not explain why finalization would even be called when program was never terminated.
Ansistring was just an example.
PascalDragon probably meant: any managed type.

And finalization has nothing to do with if your program terminates.

It probably has more to do, if a used managed Type goes out of scope.

As far as i understood it:
Unit1 uses Unit 2
Unit 2 uses Unit 3, which PROVIDES a managed type (e.g. UnicodeString).
Unit 2 does its calculations USING the type from Unit 3.
Unit 2 finishes its calculations and returns control back to Unit 1.
In that case Unit 2 would get an implicit finalization

At least that's how i understand it
« Last Edit: January 14, 2026, 02:46:25 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #19 on: January 14, 2026, 02:44:31 pm »
Considering Ansi vs Unicode strings does not have any effect: BOTH are managed string types.
@Zvoni
posts crossed.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Zvoni

  • Hero Member
  • *****
  • Posts: 3242
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #20 on: January 14, 2026, 02:48:57 pm »
Considering Ansi vs Unicode strings does not have any effect: BOTH are managed string types.
@Zvoni
posts crossed.
:D :D :D
Well, as long as we "don't cross the streams" we should be fine....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

PascalDragon

  • Hero Member
  • *****
  • Posts: 6311
  • Compiler Developer
Re: unit init, finalize and init_implicit, finalize_implicit.
« Reply #21 on: January 15, 2026, 09:46:49 pm »
If finalize_implicit is only called when unit is "finalized" - implying that program has to terminate, why do i see these TDC_GAME_$$_finalize_implicit$ calls in profiling (application was not terminated to call any unit finalization)?

It might be that this is a false positive as whatever you use for profiling might associate that symbol name with some other function. Can you take a look at the generated assembly code of the unit (option -al) and what is placed around the TDC_GAME_$$_finalize_implicit$?
 
Additionally, TDC_GAME unit does not even have a initialization or finalization section at all.. why is TDC_GAME_$$_finalize_implicit$ then even in debug symbols, and why does it show up in profiling as being called?

That's the point of the implicit finalization, it's for global variables that need to be finalized, not the finalization-section.

 

TinyPortal © 2005-2018