Thread overview | |||||
---|---|---|---|---|---|
|
November 27, 2009 Potential memory leak? | ||||
---|---|---|---|---|
| ||||
Hi All, I am using QtD to do some gui stuff. As the QtD documentation described, Qt- data types should be declared with keyword "scope", so that all variables can be deallocated in a right order. I found a memory leak problem accidentally, when I executed the following code very frequently: // public QRegion united(QRegion region) {...} scope regionA = new QRegion; scope regionB = regionA.united(anotherRegion); // Good Example scope regionA = regionA.united(anotherRegion); // Bad Example I create a variable regionA and unite it with another region. The result of the function united is assigned to variable regionB. Everything is fine. The third line sounds be correct as well. A new instance will be created and then the variable regionA will be assigned to this new instance, the old instance will be deallocated as soon as the code exits its scope. However the old instance, where the variable regionA previously was pointed to, still exists. I cannot reproceduce this problem with simple D data types. But do you think this is a bug of dmd 1.051? Qian Xu |
November 29, 2009 Re: Potential memory leak? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Qian Xu | Qian Xu Wrote:
> Hi All,
>
> I am using QtD to do some gui stuff. As the QtD documentation described, Qt- data types should be declared with keyword "scope", so that all variables can be deallocated in a right order.
>
> I found a memory leak problem accidentally, when I executed the following code very frequently:
>
> // public QRegion united(QRegion region) {...}
>
> scope regionA = new QRegion;
> scope regionB = regionA.united(anotherRegion); // Good Example
> scope regionA = regionA.united(anotherRegion); // Bad Example
>
> I create a variable regionA and unite it with another region. The result of the function united is assigned to variable regionB. Everything is fine.
>
> The third line sounds be correct as well. A new instance will be created and then the variable regionA will be assigned to this new instance, the old instance will be deallocated as soon as the code exits its scope.
>
> However the old instance, where the variable regionA previously was pointed to, still exists.
>
> I cannot reproceduce this problem with simple D data types. But do you think this is a bug of dmd 1.051?
>
> Qian Xu
>
>
Hi,
You only have to use scope for top-level QObject subclasses. For anything else you should use auto. Nevertheless, it would be useful if you submit a bug report.
Thanks.
|
November 30, 2009 Re: Potential memory leak? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eldar Insafutdinov | Eldar Insafutdinov wrote:
>
> You only have to use scope for top-level QObject subclasses. For anything else you should use auto. Nevertheless, it would be useful if you submit a bug report.
Even when my application is multi-thread? I am not sure, if I can declare QPixmap also as "auto"
|
Copyright © 1999-2021 by the D Language Foundation