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
3 answers

Strong reference to `self` to keep the object alive (temporarily): evil?

I'm creating a wrapper for UIAlertView (I know about UIAlertController and about several already existing wrappers, it's also for educational purposes). Suppose it looks like this (very shortened version): @interface MYAlertView :…
2
votes
1 answer

How to transfer ownership of some heap memory out of a function?

I am trying to write a function that loads the standard output of a command-line utility (image-magick) into a member of a struct. I figure that since images can be may MB, I might as well avoid copies as much as possible. /// An image data…
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
2
votes
1 answer

MarshalByRefObject Lifetime

I have a .net WinForms application that loads plugins (dlls) into their own AppDomains, each dll gets its own AppDomain using domain.CreateInstanceAndUnwrap(). All i want is, that these objects remain connected forever (till the application…
Lukas
  • 23
  • 1
  • 3
2
votes
1 answer

Can I back a boost intrusive collection using boost pool as storage?

I understand that boost intrusive collections ultimately store references to the objects and thus that objects need their own lifetime management. I was wondering if I can simply use boost pool to manage that lifetime. When I want to store a new…
Nathan Doromal
  • 3,437
  • 2
  • 24
  • 25
2
votes
2 answers

How do I destroy an adapter before a view when the view is non modal?

I am using a certain (MVA like) pattern for all my application modules. Views are TForm descendents: TSomeView = class(TForm) ... end; Data is managed in models: TSomeModel = class public property DataSet: TDataSet read ...; end; View and…
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
2
votes
1 answer

Vector of Reference Objects?

I have a class setup analogous to this: class BlimpBase{ public: virtual ~BlimpBase(); private: virtual void lift()const = 0; }; class Blimp: protected BlimpBase{ void lift()const; }; class BlimpCarrier{ public: …
Shokwav
  • 654
  • 8
  • 19
2
votes
2 answers

Return passed reference to object

I know that we can't return a local variable by reference since it would go out of scope. I am a bit confused when it comes to returning passed references though. For instance is the below example legal or would it lead to undefined…
Veritas
  • 2,150
  • 3
  • 16
  • 40
2
votes
1 answer

Rails object lifecycle - cross-transaction objects creation and destroy

Is there a way to have objects on a Rails app that conserve their state between HTTP transactions? For example, can I initialize a Net::LDAP connection somewhere and use it to retrieve data only restarting it on lost connection?
Pedro Montoto García
  • 1,672
  • 2
  • 18
  • 38
2
votes
2 answers

Change version of a javacard applet

Consider a situation in which personalization is done on card and amount of new data are stored in javacard, If we have a small change in aplet and wants to update applet version on javacard, what would happend to previousely stored data on card, as…
Hana Bzh
  • 2,212
  • 3
  • 18
  • 38
2
votes
4 answers

Is "premature" destruction possible?

result_t work(resource_t& resource) { lock_t ___(resource); return work_impl(resource); } Is it guaranteed that the destructor of ___ will be called AFTER work_impl() returned? Or is the compiler free to destroy ___ before calling…
Joker_vD
  • 3,715
  • 1
  • 28
  • 42
2
votes
2 answers

What am I missing in the C++11 Standard?

I'm not arguing against the result of the code below, for I think it's correct to assume that a const lvalue reference and an rvalue reference, both extend the lifetime of the temporary returned from the function. What surprises me is this paragraph…
Belloc
  • 6,318
  • 3
  • 22
  • 52
2
votes
1 answer

Need guidance on Autofac custom lifetimescopes vs. multi tenancy

Scenario: I need to provide different interface implementations to the same interface definitions within the same web application (appdomain) but to different "scopes". Imagine a simple hierarchical web content structure like this (if you are not…
lapsus
  • 2,915
  • 2
  • 32
  • 61
2
votes
2 answers

Is there a way to disable binding a temporary to a const reference?

In C++ it is possible to bind a temporary to a const reference: struct A {}; int main() { const A& a = A(); } Is there any way to disable this for some particular class A so that it would be impossible to bind a temporary of this class to a…
vitaut
  • 49,672
  • 25
  • 199
  • 336
2
votes
3 answers

Does a using block keep an object alive?

For some unit tests, I want to set the CurrentCulture to a particular culture (and then reverse these changes later). As I need to do this in several places, I was thinking of writing a CultureChanger class which saves the old culture and sets the…
Joel Rein
  • 3,608
  • 1
  • 26
  • 32
2
votes
1 answer

When can we delete a frame buffer when QImage is constructed from it and potentially shallow copied?

In this question, I would like to know the best practice of maintaining the life of an external buffer object associated to QImage object. Background I am developing an uncompressed image file viewer with QT. It reads YV12 data from a file, converts…
Moto
  • 63
  • 6