Questions tagged [object-lifetime]

The object lifetime (or life cycle) of an object in object-oriented programming is the time between an object is created (also known as instantiation or construction) till the object is no longer used and then destructed or freed.

In typical case, the process is as follows:

  1. Memory allocation and binding: Calculate the size of the object (usually the alligned size of each member of the object), allocating memory space with the size of an object plus the growth later, if possible to know in advance and binding methods.
  2. Constructor call and execution: First the constructor of superclass(es) are called, then the constructor of the object.
  3. Object use.
  4. Destructor call and execution: First the destructor of the object are called, then the destructor(s) of the superclass(es).
  5. Memory deallocation and unbinding.
402 questions
2
votes
2 answers

Long lived HttpClient created by HttpClientFactory

I've read that HttpMessageHandlers are recycled every 2 minutes, but I'm not sure if a new one is assigned to an existing HttpClient? I've tested it out by using SetHandlerLifetime(TimeSpan.FromSeconds(5)); and even after 2 minutes with countless…
SpiritBob
  • 2,355
  • 3
  • 24
  • 62
2
votes
1 answer

Are pointer to a member of this allowed in object initialization?

From Aggregate initialization, set pointer to struct member, is the following code legal: struct S { int a; int* aptr; }; S s = { 3, &s.a };
2
votes
1 answer

MEF and WPF. Lifetime of lazy(of T)?

1st i'm newbie I import object/Class using lazy() now my questions are 1) what is the lifetime of my object? 2) how this object disposes? 3) if Disposed manually can MEF later reinitialize it when i issue object.value?
LooterKaka
  • 45
  • 2
2
votes
1 answer

Definition of object and instantiation

According to What is a Class and Object in C++? A Class is like a blueprint, an object is like a house built from that blueprint. You can have many houses with the same layout/floorplan (read class), but each is it's own instance (read object).…
csguy
  • 1,354
  • 2
  • 17
  • 37
2
votes
1 answer

I/O manipulator bug or temporary lifetime extension by const ref?

I tried to wrap the io manipulator std::put_money. Here's a reduced illustration: #include #include long double scale(long double f) { return f * 100.0L; } namespace acm { auto put_money(const long double &f, bool intl =…
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
2
votes
0 answers

What is the lifetime of the arrow indirection operator (operator->) return value?

While a normal overload of the arrow operator typically returns a plain pointer, as cppreference.com notes, it doesn't have to: The overload of operator -> must either return a raw pointer, or return an object (by reference or by value) for which…
R.M.
  • 3,461
  • 1
  • 21
  • 41
2
votes
1 answer

How would I give a delegate infinite life the same way as a proxy when doing cross-app-domain development?

Background I developed a custom plugin architecture using a derivation of the Observer/Event Pattern and bits and pieces of code from the following: Code Project: Plugin ManagerMicrosoft: AppDomainsDaniel Soltyka: Simple Plugin I had an issue in the…
Mike Webb
  • 8,855
  • 18
  • 78
  • 111
2
votes
1 answer

Using a temporary object to initialise thread

Is it wrong to initialise a thread using temporary thread object which can go out of scope during the thread's execution? In the program given below, I've tried the 2 methods given below and both of them ran without any error.…
Vishal Sharma
  • 1,670
  • 20
  • 55
2
votes
2 answers

Allowing a completion handler to outlive the local scope where it's created

I have a class that implements the XMLParserDelegate protocol and during initialisation it gets a string and a completion handler as the arguments. I'm trying to call completion handler after parsing of the string, but the XMLParserDelegate methods…
2
votes
1 answer

Is casting a temporary with type `int` to a reference safe?

In the following program: int Func() { int a = { 10 }; return a; } int main() { int& r = (int&)(const int&)Func(); r = 5; } r is a reference to a temporary of type int. But temporaries are destroyed immediately unless they…
Minimus Heximus
  • 2,683
  • 3
  • 25
  • 50
2
votes
1 answer

What does a implicitly defined destructor do

What does the implicitly defined destructor do? Is it just an empty function that is defined by the compiler? struct Foo { int i; }; struct Bar { int i; ~Bar() { // empty... } }; Is the destruction of Foo identical to Bar? Or does…
Krystian S
  • 1,586
  • 7
  • 23
2
votes
2 answers

Placement new base subobject of derived in C++

Is it defined behavior to placement-new a trivially destructible base object of a derived? struct base { int& ref; }; struct derived : public base { complicated_object complicated; derived(int& r, complicated_arg arg) : base {r},…
Filipp
  • 1,843
  • 12
  • 26
2
votes
3 answers

The Scope of Creating an instance of a class inside a method in java

Can anyone explain to me the scope of creating an object from a class inside a method in java, is it a bad way and wasting the resources or it's normal? The program is running but I am not sure about this step: /** * Sending Packets Method *…
2
votes
4 answers

Reference parameter lifetime

Given the following: class ParamClass {...}; class MyObject { public: void myMethod(ParamClass const& param) { _myPrivate = param; } private: ParamClass _myPrivate; } [...] MyObject obj; void some_function(void) { ParamClass…
Dan Nestor
  • 2,441
  • 1
  • 24
  • 45
2
votes
2 answers

boost::bind and reference to temp variable

Suppose I have method: void foo(const std::string& s); Can I create boost::function: boost::function f = boost::bind(foo, temp); where temp is char* that is deleted before f is called.
dimba
  • 26,717
  • 34
  • 141
  • 196