-
February 3rd, 2014, 10:51 AM
#1
Resource leak.. ?
#include<iostream>
int* func_b() {
int *c = new int;
return c;
}
int main() {
int* b = func_b();
return 0;
}
I can see that memory leak would be there in above code because I am not freeing the memory allocated using "new".
Want to know what is the best way to avoid this leak? One solution is:
int* func_b() {
int *c = new int;
return c;
}
int main() {
int* b = func_b();
delete b;
return 0;
}
Is this optimal solution? I would be great if someone can suggest alternative way.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|