Skip to content

Fix TBoldOcl publisher leak assertion during app shutdown #35

@bero

Description

@bero

Problem

During application shutdown, BoldSubscription finalization fires a leak assertion:

EAssertionFailed: ActiveSubscriptionCount = 0, PublisherCount = 1, SubscriberCount = 0
Leaks: TBoldOcl

This happens because Delphi unit finalization order causes BoldSubscription to run its leak check before TBoldSystemTypeInfoHandle (owned by a data module) is destroyed. The TBoldSystemTypeInfo.Evaluator (TBoldOcl) is still alive at that point, leaving one orphaned publisher.

Root Cause

TBoldSystemTypeInfoHandle.GetStaticSystemTypeInfo creates a TBoldOcl evaluator (line 521: fSystemTypeInfo.Evaluator.SetLookupOclDefinition(...)). This TBoldOcl inherits from TBoldSubscribableObject, which registers a TBoldPublisher.

The data module owning TBoldSystemTypeInfoHandle is freed during VCL application teardown, which runs after unit finalization — too late for the BoldSubscription finalization leak check.

Fix

In TBoldSystem.Destroy, call fBoldSystemTypeInfo.ReleaseEvaluator after freeing the system's own evaluator. TBoldSystem is destroyed during normal object cleanup (before finalization), and after that point the SystemTypeInfo's evaluator is no longer needed.

FreeAndNil(fEvaluator);
if Assigned(fBoldSystemTypeInfo) then
  fBoldSystemTypeInfo.ReleaseEvaluator;
FreeAndNil(fClasses);

ReleaseEvaluator is safe to call multiple times (FreeAndNil), so the later destruction of TBoldSystemTypeInfo is unaffected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions