[Qt-interest] Qt memory management.
Arnold Krille
arnold at arnoldarts.de
Wed Aug 18 13:33:05 CEST 2010
On Wednesday 18 August 2010 13:10:25 Ramesh wrote:
> Fine andres..
> I do agree.. but what about this case.
>
> QString a = "foo"; // "QStringPrivate" has a refcount of 1
> QString b = a;// Shallow copy of QStringPrivate, that now has a refcount of
> 2
> a = "chock" // in this case?
>
> If we change the value of a, then what about b?
>
> b should point to "foo" right. So what happens in this case, I guess
> Deepcopy occurs right?
"Copy on write" means that whatever reference gets its value changed, it
checks for the ref-counter and if that is bigger then 1, it creates its own
copy to modify.
So after »a= "chock";«, a has "chock" and b still has "foo", both with a ref-
counter of 1.
Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100818/b8d08ed3/attachment.bin
More information about the Qt-interest-old
mailing list