Questions tagged [object-destruction]

34 questions
27
votes
6 answers

Why do finalizers have a "severe performance penalty"?

Effective Java says : There is a severe performance penalty for using finalizers. Why is it slower to destroy an object using the finalizers?
unj2
  • 52,135
  • 87
  • 247
  • 375
17
votes
6 answers

Good uses of the finalize() method

This is mostly out of curiosity. I was wandering if anyone has encountered any good usage for Object.finalize() except for debugging/logging/profiling purposes ? If you haven't encountered any what would you say a good usage would be ?
Simeon
  • 7,582
  • 15
  • 64
  • 101
15
votes
4 answers

Destruction order of static objects in shared libraries

I have a main program (main.cpp) and a shared library (test.h and test.cpp): test.h: #include struct A { A() { printf("A ctor\n"); } ~A() { printf("A dtor\n"); } }; A& getA(); test.cpp: #include "test.h" A& getA() { static…
eXXXXXXXXXXX2
  • 1,540
  • 1
  • 18
  • 32
6
votes
3 answers

C++ destruction order: Calling a field destructor before the class destructor

Is there any way to call a field destructor before the class destructor? Suppose I have 2 classes Small and Big, and Big contains an instance of Small as its field as such: class Small { public: ~Small() {std::cout << "Small destructor" <<…
CK.
  • 312
  • 3
  • 13
5
votes
1 answer

Virtual class creation/destruction in delphi

This is my first post here, but I'd like to say thank you to the community because I've found solutions to my problems countless times by coming here and finding a solution in a question that had already been answered. That being said, I'd like to…
PoultrySlave
  • 193
  • 1
  • 7
5
votes
3 answers

With statement, auto-delete object

Is it possible to delete an object form inside its class? class A(): def __init__(self): print("init") self.b="c" def __enter__(self): print("enter") return self def __exit__(self, type, value,…
Rémi Baudoux
  • 542
  • 3
  • 16
4
votes
1 answer

C++17 copy elision and object destruction

From cppreference, When copy elision occurs, the implementation treats the source and target of the omitted copy/move (since C++11) operation as simply two different ways of referring to the same object, and the destruction of that object…
pterodragon
  • 429
  • 8
  • 16
3
votes
3 answers

Are static objects deleted when an exception is thrown, or just local objects?

#include #include using std::cout; using std::endl; class test { public: test() { cout<<"constructor called"<
Alok
  • 1,997
  • 2
  • 18
  • 30
3
votes
5 answers

Smart Pointers In C++

Say we have a base class and a derived. So: class base { protected: ~base(){ //... } // ... }; class derived : public base { // ... }; And now say that we have this code using the above classes…
K-RAN
  • 896
  • 1
  • 13
  • 26
3
votes
3 answers

Destroying Prefabs Object After Spawn Using collision

I currently have some objects spawning from a prefab and am attempting to destroy only one of the spawned items of that prefab. I was searching online and I found tons of different examples but I have been unable to get any of them to work. I tried…
user10355389
3
votes
3 answers

Static CComPtr Variable

Is it bad idea to have static CComPtr member variables in an application. Since we cannt control destruction of static variable and it can happen after CoUninitialze .
anand
  • 11,071
  • 28
  • 101
  • 159
3
votes
2 answers

How to delete Worker object in JavaScript?

In my web app I constantly have to re-instantiate Worker objects, because there is no way of passing new script to old existing objects. After a while, some browsers start blocking creation of new Worker objects, because their limits of Workers for…
stack item
  • 544
  • 4
  • 11
2
votes
1 answer

Visual Studio code disable code formatting for object destructuring

I'm writing web app using Koa and Typescript. In vscode i faced with unwanted code formatting: when i declare variables using object desctructing approach vscode autoformat it in multilines: deleteUser: async (ctx: Context) => { const { body:…
2
votes
1 answer

Object creation and destruction order in C++

I wrote a simple program to learn more about the order of creating and destructing objects in C++ (using Visual Studio 2015). Here it is: #include #include using namespace std; class A { public: A(string name) :…
NPS
  • 6,003
  • 11
  • 53
  • 90
2
votes
2 answers

Using placement new in a container

I just came across some container implementation in C++. That class uses an internal buffer to manage its objects. This is a simplified version without safety checks: template class Container { public: Container() : buffer(new…
1
2 3