C++ (Qt)class Test{public: Test(const char* text) : m_size(20), m_buf(0) { init(text); } ~Test() { if(m_buf != 0){ free(m_buf); } } void init(const char* text) { if(m_buf == 0){ m_buf = (char*)realloc(m_buf, m_size); } strncpy(m_buf, text, m_size-1); } const char* get() const { return m_buf; }private: const int m_size; char* m_buf;}; typedef QVector<Test*> TestVector_t; void doItNice(TestVector_t& vector){ qDeleteAll(vector); vector.clear();} void doItAsIdiot(TestVector_t& vector){ qDeleteAll(vector);} int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); const int _size = 10; { TestVector_t _vector; for(int _i = 0; _i < _size; ++_i){ Test* _test = new Test("Nice and good!"); _vector.push_back(_test); } int _count = _vector.size(); doItNice(_vector); _count = _vector.size();// Variant 1. OK! _count is valid! if(_count){ for(int _i = 0; _i < _size; ++_i){ Test* _obj = _vector[_i]; const char* _str = _obj->get(); printf(_str); } } } { TestVector_t _vector; for(int _i = 0; _i < _size; ++_i){ Test* _test = new Test("Nice and good!"); _vector.push_back(_test); } int _count = _vector.size(); doItAsIdiot(_vector);// Variant 2. FUCK! _count is fail! _count = _vector.size(); if(_count){ for(int _i = 0; _i < _size; ++_i){ Test* _obj = _vector[_i]; const char* _str = _obj->get(); printf(_str); } } } return a.exec();}