CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2009
    Posts
    6

    Is this array or vector leaking?

    Hi,

    I have written an xll (an excel dll) and it leaks like hell. Because of how it's built I have a hard time debuggin it. Could this be leaking?

    Code:
    double test() {
     int dynamicSize = 5;
     std::vector<double> v(dynamicSize);
     double* r = NULL;
     r = new double[dynamicSize];
    
     delete [] r;
     v.clear();
    }
    Thanks.
    Last edited by cilu; June 12th, 2009 at 05:39 AM. Reason: code tags

  2. #2
    Join Date
    Feb 2009
    Posts
    10

    Re: What is leaking?

    how do u know it's leaking? did u check it against any standard memory leak programs or are you just getting an assertion failure at 'delete'?

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Is this array or vector leaking?

    No, there is no leak here.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    May 2009
    Posts
    6

    Re: What is leaking?

    ashwink: When I start Excel and look at how much memory it is using, I see that it leaks.

    Cilu: Thank you, that's what I thought. It is something else.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: What is leaking?

    Where are you looking for memory usage? Hopefully not in Task Manager, because that can't indicate anything about memory leaks.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    May 2009
    Posts
    6

    Re: What is leaking?

    Yes, I did look at the task manager. If Excel is constantly eating memory when my test xll is running (and not otherwise), then memory must be leaking as far as I know. I think I found the problem though, and now Excel isn't eating memory anymore.

  7. #7
    Join Date
    Sep 2005
    Location
    London
    Posts
    208

    Re: Is this array or vector leaking?

    Quote Originally Posted by panzram View Post
    Could this be leaking?
    There are no memory leaks in the code you've posted.

    Just in case that this is a pseudo code make sure that in your implementation, test() is not returning or throwing an exception between the memory allocation and the memory release.


    Regards
    Doron

  8. #8
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: What is leaking?

    Quote Originally Posted by panzram View Post
    Yes, I did look at the task manager. If Excel is constantly eating memory when my test xll is running (and not otherwise), then memory must be leaking as far as I know. I think I found the problem though, and now Excel isn't eating memory anymore.
    OK, but don't rely on Task Manager to identify memory leaks. Use appropriate tools for that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: What is leaking?

    The task manager is only a first indication that there may be a problem. Don't trust it for anything beyond that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured