Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Memory leaks (http://www.velocityreviews.com/forums/t689780-memory-leaks.html)

CplusplusNewbie 07-01-2009 10:40 PM

Memory leaks
 
I just looked at some code which unfortunately I no longer have access
to.
To the best of my memory it was something like this:

void SomeFunc(Base*,int);

int main()
{
base Base;
otherbase Base;
SomeFunc(&base,1);
SomeFunc(&otherbase,2);
// Ignore memory leaks

}

The comment //Ignore memory leaks confused me since I didn't think
memory leaks were possible when memory allocation is non-dynamic and
is not via new.

Are there memory leak issues in this type of code?

Thank you very much.

CplusplusNewbie 07-01-2009 10:42 PM

Re: Memory leaks
 
On Jul 1, 11:40*pm, CplusplusNewbie <Comp1...@yahoo.co.uk> wrote:
> I just looked at some code which unfortunately I no longer have access
> to.
> To the best of my memory it was something like this:
>
> void SomeFunc(Base*,int);
>
> int main()
> {
> * * * base Base;
> * * * otherbase Base;
> * * * SomeFunc(&base,1);
> * * * SomeFunc(&otherbase,2);
> * * * // Ignore memory leaks
>
> }
>
> The comment //Ignore memory leaks confused me since I didn't think
> memory leaks were possible when memory allocation is non-dynamic and
> is not via new.
>
> Are there memory leak issues in this type of code?
>
> Thank you very much.


Sorry, I meant of course

Base base;
Base otherbase;

Jonathan Lee 07-02-2009 02:57 AM

Re: Memory leaks
 
On Jul 1, 6:40*pm, CplusplusNewbie <Comp1...@yahoo.co.uk> wrote:
> Are there memory leak issues in this type of code?


Not unless Base or SomeFunc() leaks. The memory used for base and
otherbase will be freed when main() exits normally. Or, if there's an
exception, the stack will be unwound.

In any event, it doesn't matter much if main "leaks", does it? The
program ends and all memory is returned to the OS...

--Jonathan


All times are GMT. The time now is 03:27 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.