Hi Niko,<div><br></div><div>    the header size calculation is also wrong.  If the byte size if the object body is &gt; 255 bytes there needs to be an additional header size word.  So something like</div><div><br></div><div>
       byteSizeOfBody := anObject class isBytes</div><div>                                       ifTrue: [....]</div><div>                                       ifFalse: [.....].</div><div><span class="Apple-style-span" style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">       headerSize := </span>byteSizeOfBody<span class="Apple-style-span" style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"> &gt; 255</span></div>
<div><span class="Apple-style-span" style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">                               ifTrue: [12]</span></div><div><span class="Apple-style-span" style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">                               ifFalse:</span></div>
<div><span class="Apple-style-span" style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">                                     [anObject class indexIfCompact &gt; 0<br>                                          ifTrue: [4]<br>
                                          ifFalse: [8]].<br></span><br><div class="gmail_quote">On Wed, Mar 14, 2012 at 1:05 PM,  <span dir="ltr">&lt;<a href="mailto:niko.schwarz@googlemail.com">niko.schwarz@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys,<br>
<br>
I haven&#39;t checked if this bug exists already, so please ignore this if it&#39;s been reported before.<br>
<br>
Bug in WAMemoryItem:<br>
<br>
sizeOfObject: anObject<br>
        | headerSize instanceSize variableSize |<br>
        headerSize := anObject class indexIfCompact &gt; 0<br>
                ifTrue: [ 4 ]<br>
                ifFalse: [ 8 ].<br>
        instanceSize := anObject class instSize.<br>
        variableSize := anObject class isBytes<br>
                ifTrue: [ anObject basicSize ]<br>
                ifFalse: [<br>
                        anObject class isWords<br>
                                ifTrue: [ Smalltalk wordSize * anObject basicSize ]<br>
                                ifFalse: [ Smalltalk wordSize * anObject basicSize // 2 ] ].<br>
        ^ headerSize + instanceSize + variableSize<br>
<br>
<br>
In this snippet, the units that are added together in the last line are of different units.<br>
<br>
instanceSize is in unit &quot;number of machine words&quot;, whereas variableSize and headerSize are in unit &quot;bytes&quot;.<br>
<br>
<br>
The method is fixed here:<br>
<br>
sizeOfObject: anObject<br>
        | headerSize instanceSize variableSize |<br>
        headerSize := anObject class indexIfCompact &gt; 0<br>
                ifTrue: [ 4 ]<br>
                ifFalse: [ 8 ].<br>
        instanceSize := anObject class instSize * Smalltalk wordSize.<br>
        variableSize := anObject class isBytes<br>
                ifTrue: [ anObject basicSize ]<br>
                ifFalse: [<br>
                        anObject class isWords<br>
                                ifTrue: [ Smalltalk wordSize * anObject basicSize ]<br>
                                ifFalse: [ Smalltalk wordSize * anObject basicSize // 2 ] ].<br>
        ^ headerSize + instanceSize + variableSize<br>
<br>
<br>
<br>
Example:<br>
<br>
 |m|<br>
dict := Dictionary new.<br>
m := WAMemory new. dict traverseWithMemory: m seen: IdentitySet new.<br>
m totalSize<br>
<br>
This will incorrectly spit out 10, but should return 16, on a 32 bit VM.<br>
<br>
Niko<br>
<font color="#888888"><br>
--<br>
<a href="http://scg.unibe.ch/staff/Schwarz" target="_blank">http://scg.unibe.ch/staff/Schwarz</a><br>
<a href="http://twitter.com/nes1983" target="_blank">twitter.com/nes1983</a><br>
Tel: <a href="tel:%2B41786126354" value="+41786126354">+41786126354</a><br>
<br>
<br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>