Microsoft Visual Studio 2008给我以下警告:
Microsoft Visual Studio 2008 is giving me the following warning:
警告C4150:删除指向不完整类型GLCM :: Component的指针;没有析构函数调用
warning C4150: deletion of pointer to incomplete type 'GLCM::Component'; no destructor called
这可能是因为我已经定义了Handles在几个地方转发声明的类型,所以现在Handle类声称它不会调用析构函数给定对象。
This is probably because I have defined Handles to forward declared types in several places, so now the Handle class is claiming it won't call the destructor on the given object.
我有VLD运行,我没有看到任何泄漏。这真的不是为这个对象调用析构函数,或者这是一个可能不调用对象的析构函数警告?
I have VLD running and I'm not seeing any leaks. Is this literally not calling the destructor for this object or is this a "may not call destructor for object" warning?
还有另一个内存泄漏问题从我,哈哈。 / p>
Yet another memory leak question from me, haha.
推荐答案使用Pimpl时经常发生,所以我将集中在那里的解决方案:
It often happen when using Pimpl, so I'll focus on the solution there:
class FooImpl; class Foo { public: // stuff private: Pimpl<FooImpl> m_impl; };这里的问题是,除非你声明一个析构函数,否则它会自动生成,编译器。但是当然,编译器不知道 FooImpl 的完整类型。
The problem here is that unless you declare a destructor, it will be automatically generated, inline, by the compiler. But of course, the compiler will have no idea of the complete type of FooImpl there.
显式定义析构函数,即使是空的,并将定义放置在 FooImpl 的完整类型的某个位置。
You thus have to explicitly define the destructor, even if empty, and put the definition somewhere where the complete type of FooImpl is visible.
// cpp file class FooImpl { }; Foo::~Foo() {} // Empty, but now correctly generated // because FooImpl complete at this point.此外,如果像我一样,您定义了 Pimpl 类非常聪明(关于构造,复制和赋值),那么这些也需要在.cpp文件中定义。
Also, if like me you defined your Pimpl class to be pretty smart (regarding construction, copy and assignment), then those will also need to be defined in the .cpp file.
这真的是一个麻烦,那么你很好地封装了你的实现细节,所以我想这是值得的。
It's really a hassle, but then you have nicely encapsulated your implementation details, so I suppose it's worth it.
更多推荐
不完全类型内存泄漏?
发布评论