Memory leaks

  • Thread starter CplusplusNewbie
  • Start date
C

CplusplusNewbie

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.
 
C

CplusplusNewbie

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;
 
J

Jonathan Lee

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top