Page MenuHomeFeedback Tracker

Const modifier inside functions/methods forcefully deleting instances that still have references
Closed, ResolvedPublic

Description

The code below demonstrates how having a const function variable a strong referenced singleton is wrongfully deleted

class InfiniteRefContainer
{
    static const ref InfiniteRefContainer s_Singleton = new InfiniteRefContainer();
    
    void InfiniteRefContainer()
    {
        PrintFormat(ToString() + "::ctor()");
    }
    
    void ~InfiniteRefContainer()
    {
        PrintFormat(ToString() + "::dtor()");
    }
    
    static InfiniteRefContainer GetContainer()
    {
        return s_Singleton;
    }
}
...
void TestRef()
{
    const InfiniteRefContainer infiniteContainer = InfiniteRefContainer.GetContainer();
    Print(infiniteContainer);
}

SCRIPT : InfiniteRefContainer<0x000002BB76842CE0>::ctor()
SCRIPT : InfiniteRefContainer infiniteContainer = InfiniteRefContainer<0x000002BB76842CE0>
SCRIPT : InfiniteRefContainer<0x000002BB76842CE0>::dtor()

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Geez changed the task status from New to Assigned.Aug 8 2022, 11:00 PM
Geez closed this task as Resolved.Jun 14 2023, 12:36 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Resolved for one of the future updates.