Thread: any leaks?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    13

    any leaks?

    Hi,

    is this properly released? or do i need to do more?

    Code:
    typedef void(Object::*Event)(void*)); //pointer to function
    Event *events = new Event[size]; //array of these pointers
    
    //some other code
    
    if(events != NULL)
    	delete [] events;

    or this one?

    Code:
    LPD3DXMESH* ppMeshTemp = new LPD3DXMESH;
    LPD3DXMESH* meshes = new LPD3DXMESH[2];
    meshes[0] = *ppMeshTemp;
    meshes[1] = *ppMeshTemp;
    
    
    delete [] meshes;
    
    SAFE_RELEASE( (*ppMeshTemp) );
    delete[] ppMeshTemp;
    because there's a pretty good chance they're leaking.
    thanks!

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    In the first one, the new's and delete's match up, and since you created an array with new, you properly used '[]' when deleting.

    In the second one, ppMeshTemp doesn't point to an array, so you wouldn't use "[]" when deleting. I'm not familiar with the macro:

    SAFE_RELEASE( (*ppMeshTemp) );

    so I don't know what it does.

    Also, you can delete a null pointer, so you don't need an if check.
    Last edited by 7stud; 10-30-2005 at 12:51 PM.

  3. #3
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Possibly a leak, to be safe I would release each one individually.

    Code:
    for( int i=0; i<2; i++ )
      meshes[i]->Release(); //Or your safe release macro
    
    ppMeshTemp->Release();
    There is no need to delete the pointers because DX's Release function does this for you, and is the proper way to do it.
    Last edited by durban; 10-30-2005 at 12:50 PM.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-02-2009, 08:57 PM
  2. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  3. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  4. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  5. COM Memory Leaks
    By subdene in forum Windows Programming
    Replies: 0
    Last Post: 06-07-2004, 11:57 AM