![]() |
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. |
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; |
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 07:52 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.