wxWidgets 有某种垃圾收集器吗?
#include <wx/wx.h>
class MyApp : public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame(NULL, -1, _("Hello World"), wxPoint(50, 50),
wxSize(450, 350));
frame->Show(true);
return true;
}
这段代码工作得很好,而且它就是那种在外面看到的代码。我在堆上分配了一个wxFrame,我从不担心内存,wxWidgets 会收集它自己的垃圾吗?
#include <wx/wx.h>
class MyApp : public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame(NULL, -1, _("Hello World"), wxPoint(50, 50),
wxSize(450, 350));
frame->Show(true);
return true;
}
This code works fine and it is the kind of code if seen out there. I allocate a wxFrame on the heap and I never worry about the memory, does wxWidgets collects it's own garbage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,这就是你应该如何使用 wxWidgets 处理窗口。该参考文献指出,您特别不得删除它们,并且您可以使用
wxWindow::Destroy
请求销毁它们。由用户操作关闭的框架的默认行为是该框架被销毁。没有这样的垃圾收集(例如,除非删除,否则
new wxString()
将会泄漏),但某些类的内存将由库自动管理。wxWidgets 窗口删除概述
AFAIK, this is how you should handle windows with wxWidgets. The reference says that you particularly must not delete them, and that you can request them to be destroyed with
wxWindow::Destroy
. The default behavior of a frame closed by user action is that the frame is destroyed.There is no garbage collection as such (e.g a
new wxString()
will leak unless deleted), but the memory for some classes will be automatically managed by the library.wxWidgets window deletion overview