First, you allocate
xyz.test[i]
using
new
, but then you deallocate it using
delete[]
. The two don't go together! Use delete on singular allocated objects and delete[] only on allocated arrays!
Also, you allocate xyz.test, but fail to deallocate it - this is causing the leak.
You said:
But I am not sure how many cells need to be allocated...It is to be allocated as and when required.I used 10 just for reference.Randomly I have to allocate cell one by one.
This means you can not store your structs in a simple C array. Instead you need a linked list. You should follow the last link posted by Albert Holguin if you don't want to implement your own.
If you are programming in C only (no C++ constructs, no templates), then check out this
article about an Implementation of a single linked list in C. It has some very good explanations.