destructor

How to exit a PHP script without calling the destructor?

♀尐吖头ヾ 提交于 2019-12-11 09:32:32
问题 Working with an MVC framework and the controller renders the page in the destructor. I am downloading a file through php, so at the end of the action the script should end. How to end the script without calling the destructor? Is there a better solution? exit and die call the destructor. 回答1: As David said: you'll need to call exit() inside a destructor to stop it. If however you just want to halt the visual output caused by these destructors but not any other side-effects (file closing,

Why does calling delete instead of delete[] on an array of class objects cause heap corruption?

旧城冷巷雨未停 提交于 2019-12-11 07:26:34
问题 Consider the code: class A { public: virtual ~A() {} }; class B : public A { public: ~B() {} }; void main () { A * array = new A[100]; delete array; } On Windows (MSVC 2010), it causes exception because delete calls HeapValidate , which then indicates the heap was corrupted. How and why does this happen? I indeed realize delete[] should be called here, and of course then there is no problem. But why does delete cause heap corruption? As far as I know, it should call a destructor for the first

Why Does Default user defined destructors in C++ increases execution time?

流过昼夜 提交于 2019-12-11 06:37:29
问题 In my project we had, 1 user defined default destructor, which was written to follow some coding standard requirements of the project. The Class of this destructor was instantiated more than 200 times, which had increased the overall response time, when this mentioned destructor was removed, I observed improvement in response time by 28 msec. Can anyone explain why this timing difference, though those were default destructors only but defined by users, which anyways will be called by the

Is object.__del__(self) the most appropriate place to flush a logging class?

一个人想着一个人 提交于 2019-12-11 06:25:14
问题 I have a custom logging class for my Python script with a flush() method which print() s the contents of a list. I would like to include flush() in the special __del__() method in case the program ends without the log being flushed. However a note in the documentation states: [...] when del () is invoked in response to a module being deleted (e.g., when execution of the program is done), other globals referenced by the del () method may already have been deleted or in the process of being

Which method can I override for cleanup task when a Tkinter.Tk window in Python?

耗尽温柔 提交于 2019-12-11 06:06:49
问题 class MainGUI(Tkinter.Tk): # some overrides # MAIN gui = MainGUI(None) gui.mainloop() But I need to do some cleanup when the window is closed by the user. Which method in Tkinter.Tk can I override? 回答1: if you want an action to occur when a specific widget is destroyed, you may consider overriding the destroy() method. See the following example: class MyButton(Tkinter.Button): def destroy(self): print "Yo!" Tkinter.Button.destroy(self) root = Tkinter.Tk() f = Tkinter.Frame(root) b1 = MyButton

Explicit destructor call is not working

别等时光非礼了梦想. 提交于 2019-12-11 05:09:13
问题 Simplified version of my c++ Class: class Class { public: Class(uint32_t size_, uint8_t val_) buf(NULL), size(size_) { buf = new uint8_t[size]; memset(buf, val_, size); } ~Class() { if(buf != NULL) { delete[] buf; buf = NULL; size = 0; } } void FakeDtor() { if(buf != NULL) { delete[] buf; buf = NULL; size = 0; } } protected: uint8_t* buf; uint32_t size; } Code of My unit test: TEST_F(Classtest, testDestructor) { Class *buff = new Class(10,10); ASSERT_NE(buff->getData(), (uint8_t*)NULL); buff-

C++ GCC 4.3.2 error on vector of char-array

◇◆丶佛笑我妖孽 提交于 2019-12-11 04:34:57
问题 It is similar in problem to this bug Question about storing array in a std::vector in C++ but for a different reason (see below). For the following sample program in C++: #include <vector> int main(int c_, char ** v_) { const int LENGTH = 100; std::vector<char[LENGTH]> ca_vector; return 0; } GCC 4.2.3 compiles cleanly. GCC 4.3.2 emits the following errors: /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = char [100]]’:

Object not being destroyed until end of the script if it registers spl_autoload_register();

不问归期 提交于 2019-12-11 04:29:54
问题 Object not being destroyed before script ends can someone explain why using spl_autoload_register() prevents object from destruction when unset() . The destructor method will be called as soon as there are no other references to a particular object, or in any order during the shutdown sequence. Does spl_autoload_register() have reference to the object that registered it or what happens? class MyAutoLoader { public function registerAutoLoader() { spl_autoload_register(function ($class) { }); }

Using members of base class after destruction of derived class

妖精的绣舞 提交于 2019-12-11 04:29:01
问题 Suppose that we have a simple struct: struct RefCounters { size_t strong_cnt; size_t weak_cnt; RefCounters() : strong_cnt(0), weak_cnt(0) {} }; From implementation point, the destructor RefCounters::~RefCounters should do nothing, since all its members have primitive type. This means that if an object of this type is destroyed with explicit call of destructor (but its memory is not deallocated), then we would be able to work with its members normally after the object is dead. Now suppose that

How do I cleanup an opened Process in Java?

余生长醉 提交于 2019-12-11 04:24:42
问题 I'm starting a Process from a Java program. I hold onto it and at later points in the program I may send it some signals (not as in UNIX signals -- a different mechanism) to tell it to clean itself up and shut down, which is the proper way of terminating this process. I may later restart and hold onto the process and stop it again an arbitrary number of times. I'd like my program, when it exists, to signal the Process to terminate and make sure it exists. Otherwise, since Java starts the