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

Should objects created by an IDisposable that reference their creator dispose of that creator?

I have a class that implements IDisposable according to this pattern because it contains a reference to HttpClient. It looks something like this: public class CustomServiceClient : IDisposable { HttpClient client; // ... public…
Andrew Gaspar
  • 528
  • 1
  • 4
  • 8
0
votes
6 answers

How can I safely and timely dispose a scarce shared resouce in Java?

In a parallel application, threads(32) in a thread group use a shared unmanaged and standalone disposable object. We have the same thing in our c/c++ app, and there I use shared_ptr<> in order to let object dispose and finalize just after there is…
user2889419
0
votes
3 answers

C++ variable lifetime -- need workaround to return temporary

I have a C++ object (boost::format) that has a str() function which returns an std::string. So when I need a formatted C string, I need to write something like: (boost::format("%1% %2%") % "1" % "2").str().c_str() I find that rather verbose, and I…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
0
votes
1 answer

Variable lifetime in static list

this code adds a new object to a static list, within a function. the list is passed by reference to the function. what in the lifetime of the new object in the list? code sample: #include #include #include using namespace…
user1438233
  • 1,153
  • 1
  • 14
  • 30
0
votes
2 answers

C++ hinting/warning for returned reference lifetimes

I have a not-so-ideal situation where a class returns handle references to objects that shouldn't be accessed after the parent objects' lifetimes. What is the best way to alter the pattern below to aid defensive coding? // 'A' is a thin…
Jeff
  • 3,475
  • 4
  • 26
  • 35
0
votes
0 answers

How to avoid creation of a view if it is already exist

I have a listbox which looks like this: There are several…
Oleg Ignatov
  • 877
  • 2
  • 8
  • 22
0
votes
4 answers

How to make my object live even my app closed

I got a situation where i have two APPS for simplicity keep it as APP1 and APP2, i am passing an object remoteCallback as CALLBACK from APP1 to APP2 for future use. where based on result APP2 will instantiate a method updateStatus(String msg) using…
Vishal Santharam
  • 1,963
  • 1
  • 16
  • 30
0
votes
1 answer

Is it possible/legal to return reference to input temporary arguments which are passed by reference

My question is : is it legal to return a reference to an input variable which is passed by reference. I borrow the example from C++: Life span of temporary arguments? and return by rvalue reference #include #include class…
liangbright
  • 142
  • 1
  • 9
0
votes
1 answer

static object references needed to be collected in c#

My Code is basicly like that: Collecting frames from webcam on every 100ms in this method. MutexControl.Image.WaitOne(); image = null; image = (Bitmap)eventArgs.Frame.Clone(); Bitmap Myimage = new…
0
votes
2 answers

Preventing the destruction of member variables

I suspect it is not possible, but in the situation below having created A and B I'd like to reuse B (by placing it into a stack ready for reuse) but delete A. They are two of many classes derived from the parent class and I'd like the code…
mycroft.holmes
  • 177
  • 1
  • 1
  • 6
0
votes
1 answer

Store objcets in singleton class

Is it good idea store my data objects in static variables of singleton class? I have class AppEngine where are some data static e.g. boolean int and instances of my classes (Configuration etc.) When these objects are destroyed? If I want to use them…
SpeedEX505
  • 1,976
  • 4
  • 22
  • 33
0
votes
1 answer

Why can we non-const reference to a temporary object and prolong its lifetime?

#include using namespace std; struct A { A() : _p(new int(1)) {} ~A() { *_p = 0; delete _p; _p = nullptr; } int* _p; }; int main() { // // Let r_to_a reference to a…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
0
votes
1 answer

C#: Pattern for Getter with automatic dispose

Problem: I have a provider class MyProvider that delivers DataContext instances to other handler. MyProvider keeps DataContext instances open for reuse. As this behaviour consumes a lot of memory I wanted MyProvider the create an instance of the…
user946924
  • 65
  • 6
0
votes
5 answers

Problem with storing COM pointers in global singleton object

Background The application I am working with has several COM DLLs. One of the COM DLLs has a global singleton object, which stores pointers to COM interfaces in other DLLs. Because it is a global singleton object, I have employed the lazy…
0
votes
4 answers

Linq to Sql DataContext life cycle in a WCF service

I have a service exposed via WCF. The service exposes several methods that talk to the database through a Linq to SQL datacontext. The datacontext is bound to the CallContext. All of this is working as it should but I can't figure out the proper…
Ali Kazmi
  • 3,610
  • 6
  • 35
  • 51
1 2 3
26
27