I saw in the code next statement:
SomeType someVar[1];
Later someVar
is used as a pointer to SomeType
. Why would one
SomeType someVar[1];
allocates memory on the stack and it gives you a block/function scoped variable. So it will be automatically destroyed when it is out of the block/function.
SomeType* someVar;
is a pointer (to nothing meaningful yet), so it doesn't allocate any for SomeType
. However if you have something like this:
SomeType* someVar = malloc(sizeof(SomeType));
of equivalent:
SomeType* someVar = new SomeType(...);
Then that is memory allocation on the heap. So it is not destroyed when out of scope and it needs to be destroyed manually by free
or delete
.