freeing a variant array

Hi;

I have an array allocated like this:

[code]
var
MyArray : Variant;
begin
MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
end;
[/code]

As it can be seen, it is a two dimensional array.

Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?

As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?

Comments

  • [b][red]This message was edited by zibadian at 2005-2-1 6:26:14[/red][/b][hr]
    : Hi;
    :
    : I have an array allocated like this:
    :
    : [code]
    : var
    : MyArray : Variant;
    : begin
    : MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
    : end;
    : [/code]
    :
    : As it can be seen, it is a two dimensional array.
    :
    : Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?
    :
    : As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?
    :
    For most types, Delphi uses has an automatic garbage collection. Objects (especially those which depend on interfaces), and Handles are not included, as are those types described by the help description of Finalize(). If you're running Win2k or WinXP, you can check the memory usage for any memory leaks. It is however a good practice to deallocate, free, dispose all dynamic variables, whether they are part of the garbage collection or not.
    Owned persistent objects are automatically freed by their owners.
  • So how can i deallocate in this case?

    : [b][red]This message was edited by zibadian at 2005-2-1 6:26:14[/red][/b][hr]
    : : Hi;
    : :
    : : I have an array allocated like this:
    : :
    : : [code]
    : : var
    : : MyArray : Variant;
    : : begin
    : : MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
    : : end;
    : : [/code]
    : :
    : : As it can be seen, it is a two dimensional array.
    : :
    : : Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?
    : :
    : : As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?
    : :
    : For most types, Delphi uses has an automatic garbage collection. Objects (especially those which depend on interfaces), and Handles are not included, as are those types described by the help description of Finalize(). If you're running Win2k or WinXP, you can check the memory usage for any memory leaks. It is however a good practice to deallocate, free, dispose all dynamic variables, whether they are part of the garbage collection or not.
    : Owned persistent objects are automatically freed by their owners.
    :

  • : So how can i deallocate in this case?
    :
    : : [b][red]This message was edited by zibadian at 2005-2-1 6:26:14[/red][/b][hr]
    : : : Hi;
    : : :
    : : : I have an array allocated like this:
    : : :
    : : : [code]
    : : : var
    : : : MyArray : Variant;
    : : : begin
    : : : MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
    : : : end;
    : : : [/code]
    : : :
    : : : As it can be seen, it is a two dimensional array.
    : : :
    : : : Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?
    : : :
    : : : As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?
    : : :
    : : For most types, Delphi uses has an automatic garbage collection. Objects (especially those which depend on interfaces), and Handles are not included, as are those types described by the help description of Finalize(). If you're running Win2k or WinXP, you can check the memory usage for any memory leaks. It is however a good practice to deallocate, free, dispose all dynamic variables, whether they are part of the garbage collection or not.
    : : Owned persistent objects are automatically freed by their owners.
    : :
    :
    :
    Just try to use Finalize() or assign an Unassigned to the variable. That should do the trick.
  • So if the contents are also pointers those point to some other memory portions, with a call to Finalize, they will also be freed automatically?

    (because in this case, since the array is two-dimensional,
    its contents are also arrays - one dimensional arrays)


    : : So how can i deallocate in this case?
    : :
    : : : [b][red]This message was edited by zibadian at 2005-2-1 6:26:14[/red][/b][hr]
    : : : : Hi;
    : : : :
    : : : : I have an array allocated like this:
    : : : :
    : : : : [code]
    : : : : var
    : : : : MyArray : Variant;
    : : : : begin
    : : : : MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
    : : : : end;
    : : : : [/code]
    : : : :
    : : : : As it can be seen, it is a two dimensional array.
    : : : :
    : : : : Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?
    : : : :
    : : : : As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?
    : : : :
    : : : For most types, Delphi uses has an automatic garbage collection. Objects (especially those which depend on interfaces), and Handles are not included, as are those types described by the help description of Finalize(). If you're running Win2k or WinXP, you can check the memory usage for any memory leaks. It is however a good practice to deallocate, free, dispose all dynamic variables, whether they are part of the garbage collection or not.
    : : : Owned persistent objects are automatically freed by their owners.
    : : :
    : :
    : :
    : Just try to use Finalize() or assign an Unassigned to the variable. That should do the trick.
    :

  • : So if the contents are also pointers those point to some other memory portions, with a call to Finalize, they will also be freed automatically?
    :
    : (because in this case, since the array is two-dimensional,
    : its contents are also arrays - one dimensional arrays)
    :
    :
    : : : So how can i deallocate in this case?
    : : :
    : : : : [b][red]This message was edited by zibadian at 2005-2-1 6:26:14[/red][/b][hr]
    : : : : : Hi;
    : : : : :
    : : : : : I have an array allocated like this:
    : : : : :
    : : : : : [code]
    : : : : : var
    : : : : : MyArray : Variant;
    : : : : : begin
    : : : : : MyArray := VarArrayCreate([0, MaxRows, 0, MaxCols], varOleStr);
    : : : : : end;
    : : : : : [/code]
    : : : : :
    : : : : : As it can be seen, it is a two dimensional array.
    : : : : :
    : : : : : Is [code]Finalize(MyArray)[/code] enough to free this "two-dimensional" array?
    : : : : :
    : : : : : As a second general question, is there an automatic garbage collection mechanism in Delphi? That is, should we care about deallocation of memory after use?
    : : : : :
    : : : : For most types, Delphi uses has an automatic garbage collection. Objects (especially those which depend on interfaces), and Handles are not included, as are those types described by the help description of Finalize(). If you're running Win2k or WinXP, you can check the memory usage for any memory leaks. It is however a good practice to deallocate, free, dispose all dynamic variables, whether they are part of the garbage collection or not.
    : : : : Owned persistent objects are automatically freed by their owners.
    : : : :
    : : :
    : : :
    : : Just try to use Finalize() or assign an Unassigned to the variable. That should do the trick.
    : :
    :
    :
    Probably, but I've never used Variant arrays, so I'm not sure. Just create a test project and check the memory-usage of the project as you allocate and deallocate the array.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories