My question is about AnsiString in Borland C++Builder 6.0
As you know, VCL's AnsiString uses reference counting.
Is that reference counting thread safe?
For example, suppose we have std::queue<AnsiString> asq;
We push an AnsiString value in that queue in thread#1, and then we do asq.pop()
in thread#2. (The access to asq
itself is synchronized.) Strings are not modified.
Is it possible I will have a memory leak when AnsiString's destructor is called when using AnsiString(s) that way?
Asked
Active
Viewed 103 times
0

CITBL
- 1,587
- 3
- 21
- 36
-
`AnsiString`s are thread safe However you might encounter a memory leak in it ... if the case its most likely related to this [bds 2006 C hidden memory manager conflicts (class new / delete vs. AnsiString)](https://stackoverflow.com/q/17698102/2521214) compiler bug instead. – Spektre Jun 03 '20 at 10:45
1 Answers
1
Yes, the refcount is thread-safe. The RTL places a lock on the refcount whenever it is being incremented and decremented. There will not be any memory leak in the scenario you describe.

Remy Lebeau
- 555,201
- 31
- 458
- 770