Is QIcon implementation leaking?
-
QAbstractButton abs;
abs->seticon(QIcon("hello.png"));As far as I understand the Creation of QIcon, it makes the d->ref to increment and the same happens when we setIcon. So QIcon("hello.png") would have 2 refs. Then we have a deref through the destruction of the object in the parameter and we have a d->ref with value 1 at the end, what makes the QIcon data to not be deleted. So How can I delete this data? I mean, I need deref it with the abs variable, but doesn't seem to have a way to do so. I think that there is something wrong here, any ideas?
-
Nothing's leaking here.
QIcon is implicitly shared class and the button has an instance of it. When you set an icon like this a temporary icon is made (ref 1), then internal icon data is shared with the instance in the button (ref 2) and then the temporary is destroyed (back to ref 1). When the button is destroyed the icon member is destroyed too, so ref goes to 0 and releases the data. Again - nothing's leaking.If you want to remove that data earlier then just set a null icon, which will free the previous one.
-
Nothing's leaking here.
QIcon is implicitly shared class and the button has an instance of it. When you set an icon like this a temporary icon is made (ref 1), then internal icon data is shared with the instance in the button (ref 2) and then the temporary is destroyed (back to ref 1). When the button is destroyed the icon member is destroyed too, so ref goes to 0 and releases the data. Again - nothing's leaking.If you want to remove that data earlier then just set a null icon, which will free the previous one.
@Chris-Kawa Hi Chris, thanks for the answer. Would you know in Which destructor does it happen? I was using this oportunity to dive into the code so it would be more helpful
-
The icon is a member of QAbstractButtonPrivate. It has no destructor specified, but it is implicit as part of the usual C++ class instance destruction process.
-
The icon is a member of QAbstractButtonPrivate. It has no destructor specified, but it is implicit as part of the usual C++ class instance destruction process.
@Chris-Kawa Oh, you are totally right, I totally forgot about it! Just wondered about Qt destructors...