Sign in to follow this  

Deleting Matricies and Vectors

This topic is 4091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Since a D3DXVECTOR3 and a D3DXMATRIX are structs contianing only floats is it necissary to delete them? if so, how do you do it as ive found that using delete or SafeDelete() (which just checks if the pointer is NULL first) dont work. thanks

Share this post


Link to post
Share on other sites
If you have allocated them with new, then you need to deallocate them with delete, if you have just created them on the stack you shouldn't delete them:
Correct:

D3DXVECTOR3 a;
D3DXVECTOR3 *b = new D3DXVECTOR3;
D3DXMATRIX c;
D3DXMATRIX *d = new D3DXMATRIX;
delete b;// b is allocated on the heap and should be deleted.
delete d;// d is allocated on the heap and should be deleted.


Wrong:

D3DXVECTOR3 a;
D3DXVECTOR3 *b = new D3DXVECTOR3;
D3DXMATRIX c;
D3DXMATRIX *d = new D3DXMATRIX;
delete a;// Should give an error since you can't delete stack objects
delete c;// Should give an error since you can't delete stack objects
// Memory leak, b and d is never freed.


This is the same for all other objects if they are allocated on the stack the destructor automatically takes care of everything. If they are allocated on the heap you have to deallocate them, no matter whether they are ints or complex ADTs. DirectX uses some technology known as COM, when you accquire a pointer from COM you should delete it with delete, you should instead "release" it as you most likely have tried, this only works with technology built upon COM though.

Share this post


Link to post
Share on other sites

This topic is 4091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this