Project

General

Profile

Actions

Support #1106

closed

Manage the memory

Added by Arribe Barthelemy about 13 years ago. Updated about 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
12/16/2011
Due date:
% Done:

0%

Estimated time:

Description

Hi all,

Can you give an explanation to manage the memory ?

I'm checking my wt programs with valgrind and it seems that it change between the classes.

For example, this code :

textResourceFileContainer::textResourceFileContainer()

{

// create a file resource

txtFile = new WFileResource("plain/text", "./data.txt");

// the file name to create

txtFile->suggestFileName("data(copy).txt");

// create a link to download which its name is "data adescargar"

WAnchor *anchor = new WAnchor(txtFile, "data a descargar", this);

// create a new window to download

anchor->setTarget(TargetNewWindow);

}

textResourceFileContainer::~textResourceFileContainer(){

delete txtFile;

}

If I call the WFileResource like the WAnchor, Valgrind says me that I have a memory's problem.

Therefore, I have programs where I have a pointer in attributes of my class. Valgrind says the delete of this attribute make a pb of memory.

After that, it's possible it's my fault because of my way of programming, I dont know.

Thanks a lot

Bart.

Actions #1

Updated by Koen Deforche about 13 years ago

Hey,

You indeed need to manage the ownership of widgets / resources correctly.

Widgets are owned by the parent that contains them, and this is usually what you want so you do not need to delete them yourself.

Resources are not owned by the widget that uses them, since they could be shared. But you can parent them also with any WObject. So you could do the following which binds the scope of the file resource to the current widget:

 txtFile = new WFileResource("plain/text", "./data.txt", this);

Regards,

koen

Actions #2

Updated by Arribe Barthelemy about 13 years ago

Ok, I understand better now.

Thanks a lot.

Bart

Actions #3

Updated by Koen Deforche about 13 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF