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 2 2683
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 }
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Clacy |
last post by:
When exiting function scope, which occurs first:
a) destruction of local objects
b) copy of value for return
From disassembly of a debug target, it looks like the return value is copied
before local objects are destroyed. Is this standard behaviour? Can the same
behaviour be expected for any optimisation level?
As an example, in the function 'int A::fn()' here, is 'b' destroyed before
'i' is copied or vice-versa?:
|
by: ceo |
last post by:
Hi there,
I'm reffering to a text that says following:
"To summarize: When a copy of an object is generated because it passed
to a function, the object's constructor function is not called.
However, when the copy of the object inside the function is destroyed,
its destructor is called.
By default, when a copy of an object is made, a bitwise copy occurs.
|
by: Matthias Kaeppler |
last post by:
Hello,
during a discussion on a C++ internet forum, some question came up
regarding references and the lifetime of the objects they alias.
I can't find any clear wording on that in the draft standard. Example
12.2 in the standard document illustrates that temporaries bound to
references-to-const live as long as the reference does.
But does it e.g. matter if the temporary was created in scope of a
function body and has to outlive the...
|
by: Matthias Kaeppler |
last post by:
Hi,
say I have a class X, such that:
class X
{
A a;
B b;
C c;
...
|
by: Charles Law |
last post by:
I have an application that creates a class. The class has unmanaged
resources, so must end gracefully.
How can I guarantee that the unmanaged resources are freed?
I have looked at IDisposable, but this seems to rely on a call from the
application, e.g.
MyClass.Dispose()
| |
by: Simon |
last post by:
Hi,
I have written an ActiveX object to resize images and upload them to a
database, this all works fine but when I close internet explorer the
process iexporer.exe is still running in my task manager and I can not
launch anything from the desktop (eg. a web shortcut) without firt
killing this process. The object is launched using JScript with the
following code:
var Launcher = new ActiveXObject("LaunchControl");
|
by: gg9h0st |
last post by:
i worte a simple code below.
------------------------------------------------------------------------------------
#include "stdafx.h"
class Object {
public:
int a;
|
by: MikeT |
last post by:
This may sound very elementary, but can you trap when your object is
set to null within the object?
I have created a class that registers an event from an object passed
in the constructor. When my object is destroyed, I want my object to
un-register this event. If I don't then the object would never be
destroyed until the object I passed in the constructor is destroyed.
I have implemented a Dispose(), Dispose(bool), and ~Finalize...
|
by: Mortimer |
last post by:
Hi, i'm using PHP 5.1
I have two objects and the second one is using an instance of the
first.
As displayed in the example below, the Garbage Collector calls the
destruct method of the first class before the second even if the second
contains a reference to the other, so i can't complete all the
operations not having all "the code available"!
Thank you
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |