Recent

Author Topic: Management of Arrays??  (Read 3930 times)

jshand2010

  • Full Member
  • ***
  • Posts: 234
Management of Arrays??
« on: November 12, 2010, 09:02:48 pm »
i use the following format to control my arrays

type
  Shoe.....;

ss: array[1..200] of Shoe;

Since those arrays are automatically slotted in memory when the program starts.  When the program ends, that array allocation still exists, hogging memory.  i would like to know how to clear the array from memory when the program comes to terminate

any help appreciated
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10175
  • FPC developer.
Re: Management of Arrays??
« Reply #1 on: November 12, 2010, 09:15:19 pm »
Static arrays have the lifetime of the program. When the Operating system cleans up the ended program, it deallocates the memory with it.

If it is dynamic memory (e.g. TShoe is a class), the OS still deallocates, but it can be beneficial to deallocate it out of housekeeping reasons (*). Then you''l probably want to walk the array and .free them.


(*) In my work app, I have nearly all deallocations under ifdef, an ifdef that I only enable for debugging purposes.

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Management of Arrays??
« Reply #2 on: November 13, 2010, 02:11:05 pm »
i would like to know how to clear the array from memory when the program comes to terminate
for i := 1 to NShoes do ss.Free;

you are not to do anything about the array itself (200 references) but you should destroy the objects themselves.

jshand2010

  • Full Member
  • ***
  • Posts: 234
Re: Management of Arrays??
« Reply #3 on: November 14, 2010, 08:22:48 pm »
thanks for your help.  much appreciated
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

 

TinyPortal © 2005-2018