[5.22 beta 1] InitializeStructure() memory leak
Posted: Wed Mar 05, 2014 3:21 pm
If you call 'InitializeStructure()' two times in a row it also allocates memory two times without freeing the memory used before.
I assume this behaviour because I get no error if I initialize the structure with some random data. It would be great if 'InitializeStructure()' only initializes dynamical objects which were not initialized before.
The other solution for me is if 'ClearStructure()' would only deinitialize the dynamic objects without clearing all other "normal" members of the structure. Maybe with an optional parameter?
Background information: I want to be able to do this:
I assume this behaviour because I get no error if I initialize the structure with some random data. It would be great if 'InitializeStructure()' only initializes dynamical objects which were not initialized before.
The other solution for me is if 'ClearStructure()' would only deinitialize the dynamic objects without clearing all other "normal" members of the structure. Maybe with an optional parameter?
Code: Select all
Structure test
List a.i()
EndStructure
*a.test = AllocateMemory(SizeOf(test))
;Poke some invalid pointer into the address
PokeI(*a, 1234)
Debug PeekI(*a)
;No error because of wrong pointer
InitializeStructure(*a, test)
Debug PeekI(*a)
;test\a gets a new pointer
InitializeStructure(*a, test)
Debug PeekI(*a)
Code: Select all
Structure test
*vTable
List a.i()
EndStructure
Structure test2 Extends test
member.i
EndStructure
*a.test = AllocateMemory(SizeOf(test2))
InitializeStructure(*a, test)
*a\vTable = 123
ClearStructure(*a, test)
*b.test2 = *a
InitializeStructure(*a, test2)
*b\member = 456
Debug *b\vTable
Debug *b\member