Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Does this leak memory

struct some_struct {

}

std::vector<some_struct *> list_of_struct;
list_of_struct.push_back(new some_struct());

some_struct* remove_first_member() {
	std::vector<some_struct *>::iterator it( list_of_struct.begin());
	some_struct  *temp = *it;
	 list_of_struct.erase(it);
	return temp;
}

// somewhere in main I am calling
remove_first_member(); // There is no lvalue even though the function returns pointer
                                        // to some_struct

Open in new window


Will this leak memory?
0
perlperl
Asked:
perlperl
  • 2
1 Solution
 
perlperlAuthor Commented:
OR should I do something like this to avoid memory leak?

some_struct* temp = remove_first_member();
delete temp;
0
 
perlperlAuthor Commented:
I got it. I added printf in destructore to verify it. I was leaking memory. I have to delete it as I mentioned in the second comment.

Can the admin please close the Q
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now