Wt 3 memory deallocation
Wt 3 memory deallocation
主要是很明显在wt 3中对内存的位置(在wt 4中非常明确),但是在这种情况下,我不了解逻辑。
以下功能内容为我的WT 3应用程序设置一个容器。一切都很好,但是谁能解释如何(或应该这样)返回_ content?
_content作为私人类数据。
Wt::WContainerWidget* _content;
功能内容()句柄容器
Wt::WContainerWidget* web::content()
{
if (_content == 0) {
_content = new Wt::WContainerWidget(root()); //memory allocation
}
return _content; //allocated memory gets returned
}
以后使用的是:
void web::sayhi()
{
content()->addWidget(new Wt::WBreak());
content()->addWidget(new Wt::WText("hello world"));
}
该如何删除/处理由content()
如果使用这种形式的构造函数:
_content = new Wt::WContainerWidget(root());
然后小时候将小部件添加到root()
中,因此由root()
拥有。在这种情况下,_content
实际上是不持有的。
所以,当WApplication
被销毁时,root()
和root()
的每个孩子都被它销毁。
这等同于在wt 4:
中这样做_content = root()->addWidget(std::make_unique<Wt::WContainerWidget>());
或较短(自WT 4.0.1以来):
_content = root()->addNew<Wt::WContainerWidget>();
您应该将内容存储为一个由值而不是指针存储的变量成员。如果您必须将内容保留为指针,则可能需要探索智能指针的使用(std :: simelod_ptr或std :: shared_ptr)
相关文章:
- Python ctype 'c_char_p' Memory Leak
- 模式"allocate memory or use existing data"
- Win32 API - HWND "{unused = ???} Unable to read memory"错误
- "in-situ without memory allocation" 字符串的愚蠢实现意味着什么?
- C++ "Using Uninitialized Memory.. (variable name) "
- "Memory Fragmentation"这仍然是一个问题?
- 封送指向结构异常"cannot Read or Write protected memory"的指针数组的指针数组
- 向量数组"Cannot access memory at address"
- 什么是"Reading unbounded stream from standard input (Memory Management)"的例子
- 我在 C++ "out_of_range at memory location"有问题
- QML QQmlPropertyList - 包含的对象生存期和'memory rules'
- Java 本机访问代码错误:"Invalid memory access"
- 编写"anti-lack of memory"异常安全代码
- 什么__asm挥发性("pause" ::: "memory");男孩
- 将 Dr. Memory 与 Visual Studio 项目配合使用时出错:缺少应用程序所需的库
- 如何修复代码中的"Invalid memory reference"错误?
- 如何找到导致"malloc(): memory corruption: 0x00"的线
- UrlDownloadToFile to Memory
- 如何安全地实施"Using Uninitialized Memory For Fun And Profit"?
- Wt 3 memory deallocation