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
4
votes
1 answer

Is this undefined behaviour or a bug with struct init?

Please consider this bit of code: #include int main() { struct A { int x; int y; int z; int foo() { std::cout << "enter foo: " << this->x << "," << this->y << "," <<…
4
votes
2 answers

Why do I need to dispose of subscriptions after completion?

The Intro To RX book describes the return value on OnSubscribe as IDisposible and notes that subscriptions should be disposed of when OnError and OnCompleted are called. An interesting thing to consider is that when a sequence completes or …
4
votes
2 answers

What are the changes, if any, to the memcpy lifetime initalization rules in the new standard?

As far as I am aware, memcpy into uninitialized storage cannot safely be used to create an copy of the source object. However, in this thread from last year on the open-std WG21 "ub" list, a participant refers to the new memcpy lifetime-initiation…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
4
votes
4 answers

The correct way to release variables in Objective-c

I know that in Objective-c there's a very easy way to declare variables like this: NSArray* myArray; @property(retain) NSArray* myArray; @synthesize myArray; This way you can use self.myArray as both the setter and getter while retaining the…
Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
4
votes
3 answers

At what point does a controller class instantiate a controller object in a Rails web app?

Learning Rails, the point at which a controller gets instantiated is unclear to me whereas, the point at which a model gets instantiated is somewhat recognizable as for example, when a user enters data in a from and clicks the submit button is sort…
dragon
  • 101
  • 4
4
votes
2 answers

Lifetime of const references bound to destroyed stack variable

I'm wondering if it's by chance a pointer to const reference bound to a destroyed stack variable can be working. I read const reference lifetime is extended on rvalues, so this is "normal" const reference works but at the end of the ctor of Storage…
Richard Dally
  • 1,432
  • 2
  • 21
  • 38
4
votes
1 answer

Why AppDomain.GetLifetimeService returns null?

My application uses AppDomain in order to load a dll. If i don't call methods from the AppDomain for more than 5 minutes, when I call a method again I get this error: Object '[...].rem' has been disconnected or does not exist at the server. I…
Homer1982
  • 441
  • 4
  • 16
4
votes
1 answer

Explicit lifetime error in rust

I have a rust enum that I want to use, however I recieve the error; error: explicit lifetime bound required numeric(Num), ~~~ The enum in question: enum expr{ numeric(Num), symbol(String), } I don't think I understand what is being…
ragingSloth
  • 1,094
  • 8
  • 22
4
votes
1 answer

Multiple constructor with Structuremap changing the scope?

To illustrate the problem, here is a simplified version of my setup. I have a factory like this one : public interface IFactory{ } public class Factory : IFactory { public Factory() { Console.WriteLine("parameterless"); } …
Stéphane
  • 11,755
  • 7
  • 49
  • 63
4
votes
1 answer

Life extension of temporary by const reference

C++ I'm trying to see how const references prolong the lifetime of temporaries. I'm running the code from the snippet in one of the answers to What are the differences between pointer variable and reference variable in C++? and got conflicting…
4
votes
1 answer

Dependency injection and life time of IDisposable objects

I am trying to develop a library using dependency injection approach (with Ninject) and I am having some kind of confusion likely because of my incorrect design. In summary, my design approach is A parent object has a common object. A parent object…
Mehmet Ataş
  • 11,081
  • 6
  • 51
  • 78
4
votes
3 answers

Life of a Java Object

What is the life of a Java Object that is passed a method argument? For example I have an object Test class Test{ public string testType(){ ..... } } and I have two classes A and B class classA{ classB b = new classB(); void…
user1216750
  • 483
  • 3
  • 10
  • 17
3
votes
3 answers

What are the advantages of using a concept like IStartable?

Instead of using an interface like this: public interface IStartable { void Start(); void Stop(); } I usually just make the constructor of an object run the Start() code, and implement IDisposable so that the dispose method runs the Stop()…
3
votes
1 answer

WCF and container lifetime

I'm sure this is obvious but I haven't been able to find a very specific clean answer to the lifetime of a container in a IIS 7.5 hosted WCF service. If the container lives in my service code, it would be created on every request unless…
William
  • 1,375
  • 12
  • 27
3
votes
2 answers

c++ Object parameters: polymorphism, value semantics, object lifetimes?

As I make the transition from C# to C++ I get a lot of recommendations to use value semantics where possible. It's pretty much guaranteed that if I post a question with a pointer anywhere someone will come along and suggest that it should be a…
User
  • 62,498
  • 72
  • 186
  • 247