I have a class that contains an array of TStrings. I implement the array as a pointer, as I need to set the size of the array dynamically. In the destructor for this class, I try to delete this pointer. However, I receive the following message whenever the destructor is called:
root.exe(6163) malloc: *** Deallocation of a pointer not malloced: 0x2bd0574; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug.
The following class reproduces the problem I am experiencing:
What is the error that I am making in trying to delete this pointer? Is there a simple way to implement a dynamically-sized array so as to avoid this problem with pointers?
I have a class that contains an array of TStrings. I implement the array as a pointer, as I need to set the size of the array dynamically. In the destructor for this class, I try to delete this pointer. However, I receive the following message whenever the destructor is called:
root.exe(6163) malloc: *** Deallocation of a pointer not malloced: 0x2bd0574; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug.
The following class reproduces the problem I am experiencing:
What is the error that I am making in trying to delete this pointer? Is there a simple way to implement a dynamically-sized array so as to avoid this problem with pointers?
Thanks,
Adrian[/quote]
try: delete[] TheArray;
and
please use standard containers bicycle is already invented…
Thanks for the suggestion. I’ve changed all of my string arrays to TObjArrays of TObjStrings. However, I’m still getting malloc errors when I try to delete pointers, this time to histograms. The short class below demonstrates the behavior that I’m getting.