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

ASP .NET Application Life Cycle + Singleton Instance Life Time

Please considerer the following scenario : I have created a full-web application by using the ASP .NET MVC 3 framework. Now my application is managed by a web server. An HTTP request is received on the server-side of my application. A class…
user1139666
  • 1,687
  • 4
  • 24
  • 45
2
votes
1 answer

One object per HttpContext instance

I'm currently writing a project in ASP.NET MVC. I have a web project and DB project which solely works with DB. The layers look like this and they interoperate only with sibling layers. DB project (EF CF) - makes db requests Repository -…
Oybek
  • 7,016
  • 5
  • 29
  • 49
2
votes
2 answers

Object Lifetime and undefined behavior

In the 3.8 Object lifetime, there is the following section Before the lifetime of an object has started but after the storage which the object will occupy has been allocated40 or, after the lifetime of an object has ended and before the storage…
getsoubl
  • 808
  • 10
  • 25
2
votes
1 answer

Can a pointer to a memory be used as initialized trivial type?

Is it undefined behavior to use a trivial type without initialization? void* mem = malloc(sizeof(uint64_t)*100); void* num_mem = mem + sizeof(uint64_t)*31; //does the lifetime of uint64_t starts here: uint64_t* mynum =…
Arkady
  • 2,084
  • 3
  • 27
  • 48
2
votes
1 answer

How to solve "Returns a value referencing data owned by the current function" (Actual depenecies between structs)

I'm learning Rust (I'm a C++ dev) and I'm still getting used to the borrow checker. I have the following example (which is also on godbolt: https://godbolt.org/z/z873x9cPn): struct Foo { value: i32, } struct Bar <'a> { foo: &'a mut…
Pau6b
  • 23
  • 1
  • 3
2
votes
1 answer

BizTalk mapping - Scripting Functoid Object life cycle, when is it initialized and destructed

In a BizTalk map when you call a scripting functiod, is the object (the class you are calling) initialized at the time of the first call and kept in memory for the entire time the transformation is occurring? Or is is destroyed and initialized every…
aceinthehole
  • 5,122
  • 11
  • 38
  • 54
2
votes
2 answers

When does exception handling unexpectedly influence object lifetimes?

The Python reference on the data model notes that catching an exception with a ‘try…except’ statement may keep objects alive. It seems rather obvious that exceptions change control flow, potentially leading to different objects remaining…
Tau
  • 496
  • 4
  • 22
2
votes
6 answers

C++: How to manage object lifetimes and dependencies?

A concrete problem: I have a Main application which has objects of type A and type B (among other types). Object of type B requires A object to be properly constructed (so there is a constructor A(const B& b). However Main may change B object it…
user231536
  • 2,661
  • 4
  • 33
  • 45
2
votes
2 answers

What is the life time of a C++ data structure object?

Suppose I have have a Car.h which define a class called Car , and I have implementation Car.cpp which implement my class Car, for example my Car.cpp can be : struct Helper { ... }; Helper helpers[] = { /* init code */ }; Car::Car() {} char…
dan_l
  • 1,692
  • 2
  • 23
  • 40
2
votes
1 answer

Is it really UB to access an object whose user-defined destructor has started, but not finished?

The question arose due to a discussion on Reddit, where a user told me, citing the standard's rules on object lifetime: I'm pretty certain that it is technically UB to access an object, while it is being destructed. I rely on this, for example,…
Bwmat
  • 4,314
  • 3
  • 27
  • 42
2
votes
1 answer

MEF ExportFactory - How to properly dispose in a long-running application?

Basically, is there an easy way to dispose of the imports that are created by an ExportFactory? The reason I ask is because the exports usually contain a reference to something that is still around, such as the EventAggregator. I don't want to…
myermian
  • 31,823
  • 24
  • 123
  • 215
2
votes
1 answer

Object lifetime related; Does a term/pattern/whatnot exist for the following problem?

I'm trying to write a callback class for my GUI windows. To (hopefully) achieve that, I'm using delegates. typedef srutil::delegate2 CallbackMethod; typedef std::map>…
Erius
  • 1,021
  • 8
  • 21
2
votes
2 answers

MVC 3, Unity 2 - Per Request Lifetime Manager

I'm using the Unity MVC3 code at http://unitymvc3.codeplex.com/ to have a NHibernate session per request instance of my IUnitOfWork. It was working a few weeks ago, I've made some changes, and now my IUnitOfWork appears to have a static…
Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149
2
votes
2 answers

Extending the lifetime of a temporary object without copying it

Consider the following code: #include #include struct object { object(const object&) = delete; object(object&&) = delete; object() {std::clog << "object::object()\n";} ~object() {std::clog <<…
Vincent
  • 57,703
  • 61
  • 205
  • 388
2
votes
1 answer

How to yield a nilable shared object in Chapel?

Currently, I am working on Chapel Data Objects and I am facing some issues. I have a class named Row which can be nil. I have these three methods: override iter these()ref { for row in this.fetchall(){ yield row; } } …