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

Objects consumption pattern

I was trying to solve a specific problem that, in facts, is an example of a more general issue. Let' say that we have a couple of objects where one object depends on the other: Bitmap AnImage; // Several instances of this object are possible: an…
Daniel
  • 1,357
  • 2
  • 19
  • 39
0
votes
2 answers

Visual C++ runtime object destruction order

I've stumbled across a rather annoying issue relating to when the Visual C++ runtime destructs my objects as the program quits. I have a class which is used to ensure references to certain states are valid. I need to store the states for an unknown…
user1520427
  • 1,345
  • 1
  • 15
  • 27
0
votes
1 answer

Interation with EJB (and EntityManager) from singleton daemons, MDB and Web Controllers within single ear

There is an technology stack: Java EE (WebSpere), JPA, EJB3, JMS (MDB), JSF. Architecture: JMS messages arrive (via MDB) and are registered as persisted entities - (using EntityManager). There is a Singleton class with infinite loop which is…
aillusions
  • 194
  • 1
  • 15
0
votes
2 answers

How do I use a pointer to an object from one function in another function?

I have a pointer to an object which i will be using in one method. but i need to use the same pointer again in another method how can i achieve this without declaring as global object. This is part of my dynamic biding achievement Shape is the…
rasul1719435
  • 115
  • 4
  • 10
0
votes
1 answer

Detecting when an NSView is dealloc'ed

Is there any way to detect when an NSView will be dealloc'ed? The reason is, I have some simple delegates (such as an NSTextField delegate that handles -control:textView:doCommandBySelector: to allow the return/tab keys to be entered). I'd like to…
Peter N Lewis
  • 17,664
  • 2
  • 43
  • 56
0
votes
3 answers

Giving default values to reference member variables

so I've made a class in c++ which has 2 reference type members: class Edge{ private: const Node& base; const Node& target; public: Edge(const Node& new1, const Node& new2); I want to give default values to base and target in the C'tor. Which…
Jjang
  • 243
  • 1
  • 6
  • 13
-1
votes
1 answer

Android : context menu item click causes variables to change state

I'm currently trying to implement a context menu for my app, there is a list of tasks and when the user long-clicks on one, a context menu should appear giving the user some options depending on the item he selected. Implementing the menu itself…
tom gautot
  • 378
  • 2
  • 10
-1
votes
1 answer

block object usage after deletion of "this" pointer

I'm working on an application that has the following problem. Basically there are a lot of object that implicitly might destroy themselves. void Foo::func() { ... Bar b; b.func2(); } Here the func2 might destroy the foo object calling…
Frank
  • 2,446
  • 7
  • 33
  • 67
-1
votes
2 answers

Destructor for a List class in C++

I'm new to C++ thus the question. I've a toy implementation of a Singly Linked List in C++. template class List { template struct Node { U data_; Node* next_; Node() : data_(0),…
-2
votes
1 answer

Object life Time and encapsulation in C++

I have a question about the object life time and assigning values to member variables vs calling member variables via an encapsulation like a getter. In my code I want to update a member variable m_a in the CLASS2::Update() method. I then call this…
-2
votes
2 answers

Why it seems that mutex acquired via std::lock_guard still take effect for a little while after its scope

As we know, the correct usage of std::lock_guard is like this RAII style: void increase_decrease() { std::lock_guard guard(global_mutex); static const int times = 50; for (int i = 0; i < times; i++) { global_data…
Yunqing Gong
  • 775
  • 7
  • 11
-2
votes
1 answer

Order of destructors

I have these kind of classes: Game: class Game { private: BoardField*** m_board_fields; public: Game() { m_board_fields = new BoardField**[8]; for (int i = 0; i < 8; i++) { m_board_fields[i] = new…
Faustas Butkus
  • 291
  • 1
  • 5
  • 14
1 2 3
26
27