http://18delphi.blogspot.com/2015/02/containers-1-implementation-of.html

http://18delphi.blogspot.com/2015/02/containers-1-implementation-of.html

Comments

  1. Александр Люлин This looks like a logic approach to me. When creating the ref count goes one up and when destroying the ref count goes one down. And how you create or destroy the object it should make no difference. You can call free, destroy, := nill or some other manner when destroyed ref count should go down. In my opinion that is the biggest problem I had with Delphi in the past, spending a lot of time in looking for memory leaks. Lukelly there are alternatives ways using interfaces, but still you to be careful. Embarcadero should spent some time in solving this issue. They should keep track on which execution level a pointer to an object is created and increase the ref count, when leaving that level or reassigning the var that holds the pointer the ref count should be decreased, when zero the object is auto destroyed. Easy and simple logic no need to free, destroy, freeandnil or other.. Simple logic every call of a procedure or function increases the level of execution.

    ReplyDelete
  2. [16:06] МВ> procedure TForm1.Button1Click(Sender: TObject);
    var
    A: TObject;
    B: TObjectList;
    C: TObjectList;
    begin
    A := TObject.Create;
    B := TObjectList.Create(True);
    C := TObjectList.Create(True);
    B.Add(A);
    C.Add(A);
    FreeAndNil(B);
    FreeAndNil(C); <- AV
    end;

    ReplyDelete

Post a Comment