destructor

Is using php destructor appropriate for displaying HTML?

If a class is implemented that builds HTML for a page by constructing it and calling various methods, is it appropriate to define the display/echo part of the class within the destructor? Instead of having a explicit Class:displayHTML(); method, having the echo $this->html in the destructor and whenever you are ready to display call u...

Memory consuption code optimization, a garbage collector question

In my WPF-application I call new windows in the following way: _newWin = new WinWorkers_AddWorker(); _newWin.WindowState = this.WindowState; _newWin.Show(); Where _newWin is a private Window object. My question is should I assign a null value to _newWin after I call _newWin.Show()? Will this decrease memory consumption, because garb...

C++ is Virtual destructor still needed if there are no data members in derived?

Suppose I have this code class Base{ public: int getVal(); private: int a, b; }; class Derived::public Base{ public: void printVal(); }; int main(){ Base *b = new Derived(); delete b; } I know a virtual destructor would delete things properly, but is it bad to delete with base pointer (w...

delete expression

Reference here That destructor will also implicitly call the destructor of the auto_ptr object. And that will delete the pointer it holds, that points to the C object - without knowing the definition of C! That appeared in the .cpp file where struct A's constructor is defined. This was curious and then 5.3.5/5 sta...

Object-Oriented Suicide or delete this;

The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is logical. #include <iostream> class SomeClass { public: void CommitSuicide() { delete this; } void Reincarnate() { this->~SomeClass(); new (this) SomeClass; } ~SomeClass() { std::cout << "Destructor\n...

How to simulate an OnDestroy event on a TFrame in Delphi?

How can i simulate an OnDestroy event for a TFrame in Delphi? i nievely added a constructor and destructor to my frame, thinking that is what TForm does: TframeEditCustomer = class(TFrame) ... public constructor Create(AOwner: TComponent); override; destructor Destroy; override; ... end; constructor TframeEditCustomer.Creat...

How to write a class destructor in Scala?

I'd like to have a FileWriter opened during the whole time a class instance exists. So I need to close it in a destructor. But how to specify a destructor in Scala? ...

Stack unwinding in C++ when using Lua.

I recently stumbled into this this C++/Lua error int function_for_lua( lua_State* L ) { std::string s("Trouble coming!"); /* ... */ return luaL_error(L,"something went wrong"); } The error is that luaL_error use longjmp, so the stack is never unwound and s is never destructed, leaking memory. There are a few more Lua API's th...

C++ circular reference problem

Hello, I have 2 classes: DataObject and DataElement. DataObject holds pointers to (only) DataElements, and a DataElement contains pointers to several types, among which a DataObject. This used to be no problem, since I only use pointers to DataObjects in DataElement, so a forward declaration of DataObject in the header of DataElement i...

Base class's destructor called without destroying the base class!

#include<iostream> using namespace std; class A { public: int i; A() {cout<<"A()"<<endl;} ~A() {cout<<"~A()"<<endl;} }; class B:public A { public: int j; B(): j(10) { this->i=20; this->~A(); } }; int main() { B abc; cout<<"i="<<abc.i...

Order of message passing for object destruction / teardown

This is a language agnostic question about object oriented design, particularly the passing of messages regarding object destruction. This whole question could just as easily use the terms Parent and Child instead of Factory and Item. Which object should be responsible for an objects tear-down process; the object itself, or the factory...

C++ destructor code

Hi, I am have this simple C++ code, but I dont know how to use the destructor. class date { public: int day; date(int m) { day =m; } ~date(){ cout << "I wish you have entered the year \n" << day; } }; int main() { date ob2(12); ob2.~date(); cout << ob2.day; return 0; } the question i...

How to make sure your dealloc code is called on application termination?

According to NSObject's documentation: Important: Note that when an application terminates, objects may not be sent a dealloc message since the process's memory is automatically cleared on exit --- it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management ...