Delphi Error – E2256 Dispose not supported (nor necessary) for dynamic arrays

Delphi Compiler Error

E2256 Dispose not supported (nor necessary) for dynamic arrays

Reason for the Error & Solution

The compiler has encountered a use of the standard procedure DISPOSE on a dynamic array. Dynamic arrays are reference counted and will automatically free themselves when there are no longer any references to them.

The use of DISPOSE on the dynamic array arr causes the error in this example:

program Produce;
  var
    arr : array of integer;

begin
  SetLength(arr, 10);
  Dispose(arr);
end.
	

The only solution here is to remove the offending use of DISPOSE:

program Produce;
  var
    arr : array of integer;

begin
  SetLength(arr, 10);
end.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...