www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22505] New: Array relocation causes multiple calls to


          Issue ID: 22505
           Summary: Array relocation causes multiple calls to destructor
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: omerfirmak gmail.com

import std;
import core.memory;

struct B
        int[] b;
    ~this ()

void main()
        B[] b_list;
        foreach(idx; 0 ..100)
            b_list ~= B([0]);
        b_list.length = 0;


One would assume that B.b[0] would always be 0 before destructor runs. But if
b_list is ever relocated while trying to expand its size, GC will finalize
objects while trying to collect the old memory for b_list and cause all objects
in b_list to be finalized multiple times.

Nov 12 2021