By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

when is object destroyed?

P: n/a
I have the following loop:

for (int i = 0; i < n; ++i)
{
CClass newObject( i );
//
// lines of code
//
}

Since a new object is being created (is it?) for every iteration, when is
the previous object being destroyed, or is it? If not, how do I destroy
it? Do I need to, if I don't will this lead to a memory leak?

-charles

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Charles Herman wrote in <3f********@127.0.0.1>:
I have the following loop:

for (int i = 0; i < n; ++i)
{
CClass newObject( i );
//
// lines of code
//
}

Since a new object is being created (is it?) for every iteration, when is
the previous object being destroyed, or is it? If not, how do I destroy
it? Do I need to, if I don't will this lead to a memory leak?

-charles


it will be destroyed at the end of the scope
at the }
Jul 19 '05 #2

P: n/a
Charles Herman wrote:
I have the following loop:

for (int i = 0; i < n; ++i)
{
CClass newObject( i );
//
// lines of code
//
}

Since a new object is being created (is it?) for every iteration, when is
the previous object being destroyed, or is it? If not, how do I destroy
it? Do I need to, if I don't will this lead to a memory leak?


Its created each time though the loop and each time through
too (closing brace). Can be a potential bottleneck,
particularly if it allocates any memory, but you won't know
for sure unless you profile it.

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.