Does FreeBASIC frees an array inside a UDT self ?

General FreeBASIC programming questions.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Does FreeBASIC frees an array inside a UDT self ?

Post by D.J.Peters »

Look at line 22 does FreeBASIC destroys/frees the array ?

Joshy

Code: Select all

type tThing
  declare constructor
  declare constructor (byval va as integer, _ 
                       byval vb as integer, _
                       byval vc as integer)
  as integer a=any,b=any,c=any
end type
constructor tThing
end constructor
constructor tThing (byval va as integer, _ 
                    byval vb as integer, _
                    byval vc as integer)
 a=va : b=vb : c=vc
end constructor
type tTest
  declare destructor
  declare constructor
  declare sub addThing(byref thig as const tThing)
  as tThing things(any)
end type
destructor tTest
 ' does FreeBASIC frees the array things() self ? 
end destructor
constructor tTest
end constructor
sub tTest . addThing(byref thing as const tThing)
  redim preserve things(ubound(things)+1)
  things(ubound(things))=thing
end sub

dim as tTest test
test.addThing(tThing(1,2,3))
test.addThing(tThing(4,5,6))
for i as integer = 0 to ubound(test.things)
  print test.things(i).a,test.things(i).b,test.things(i).c
next  
sleep
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Does FreeBASIC frees an array inside a UDT self ?

Post by fxm »

Yes.

For a bit more information, see Variable-length member data in the Programmer's Guide.
Post Reply