Container design

We have previously dynamically allocated the arr to new int[ms].But when the cs==ms condition is achievd.We allocate the memory arr=new int(2*ts) again.Wouldn’t this cause memory leak error?

Hey @armaanbhardwaj23, it wouldn’t cause memory leak because First we are pointing an old pointer to arr then increasing size of arr to 2*ts then copying element of old pointer to new arr and then deleting old pointer array. So no memory will leak . Hope I helped :grinning: keep coding :+1:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.