File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -285,9 +285,19 @@ void Object::MemoryAccumulator::accumulate( size_t bytes )
285
285
286
286
void Object::MemoryAccumulator::accumulate ( const Object *object )
287
287
{
288
- if ( m_accumulated. find ( object )==m_accumulated. end () )
288
+ if ( object-> refCount () > 1 )
289
289
{
290
- m_accumulated.insert ( object );
290
+ // object may occur multiple times in the data structure
291
+ // being counted - ensure that we don't count it twice.
292
+ if ( m_accumulated.insert ( object ).second )
293
+ {
294
+ object->memoryUsage ( *this );
295
+ }
296
+ }
297
+ else
298
+ {
299
+ // object can only occur once in the data structure being
300
+ // counted - avoid unnecessary bookkeeping overhead.
291
301
object->memoryUsage ( *this );
292
302
}
293
303
}
Original file line number Diff line number Diff line change @@ -53,6 +53,19 @@ def testMultipleReferences( self ) :
53
53
c ["b" ] = d
54
54
self .assert_ ( c .memoryUsage () < m + dm )
55
55
56
+ def testMultipleReferencesToStringData ( self ) :
57
+
58
+ c = CompoundObject ()
59
+ d = StringData ( " " * 10000 )
60
+
61
+ c ["a" ] = d
62
+
63
+ m = c .memoryUsage ()
64
+ dm = d .memoryUsage ()
65
+
66
+ c ["b" ] = d
67
+ self .assert_ ( c .memoryUsage () < m + dm )
68
+
56
69
def testCopiedDataReferences ( self ) :
57
70
58
71
"""Copied data shouldn't use additional memory unless the copies have
You can’t perform that action at this time.
0 commit comments