StereoMatching
StereoMatching

Reputation: 5019

How to generate memory leak by QString and other implicit sharing data structure of Qt

QString and many data structure of Qt are implicit sharing

How could I make their memory leak?

Circular dependency would cause memory leak if it is shared_ptr Would QString and other QString like data structure in Qt memory leak too? I want to know how to make the memory of QString leak, so I would not fall into the trap of it.

After some study, looks like I don't have to worry about circular dependency when it is QString? Thanks to your reply, now I don't have to worry about it.

Upvotes: 0

Views: 1682

Answers (1)

odinthenerd
odinthenerd

Reputation: 5552

In versions of Qt prior to 4 concurrent access to two copies of a QString which shared the same data could cause problems because QString is COW but did not lock the ref count. This was a gotcha. As of version 4 the ref count is handled using atomics which solves the problem. You can mangle some Qt containers by putting things in them that can throw in odd places but I can't think of a way that could affect QString. Be warry of exception handling in Qt, the doc's are quite vague which usually means beware ;)

http://doc-snapshot.qt-project.org/4.8/exceptionsafety.html

If you run out of memory when running Qt expect the world to end, in that case it's probably doesn't matter if the QString leaked or not.

Upvotes: 1

Related Questions