<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 29 August 2013 18:34, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 29, 2013 at 8:54 AM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br><div dir="ltr">
<div><div><div>Hello,<br><br></div>i tried to implement a simple algorithm to find nearest common roots for some object(s).. <br></div>see the attached code.<br><br></div>The problem i discovered that the last assertion of my test fails:<br>
=====<br>testArrayShouldBeRootOfItsElements<br><br> | obj1 obj2 array arrayToTest roots |<br> <br> obj1 := 'ObjectA' copy.<br> obj2 := 'ObjectB' copy.<br> <br> array := { obj1. obj2 }.<br>
arrayToTest := { obj1. obj2 }.<br> <br> roots := CommonRootsFinder new findCommonRootsOf: arrayToTest.<br> <br> self assert: (roots identityIncludes: array).<br> self assert: (roots identityIncludes: arrayToTest) not.<br>
self assert: (roots identityIncludes: thisContext). "- sometimes works , sometimes not "<br clear="all"><div><div><div><div>========<br><br></div><div>but, when i restart the method in debugger and step down through it, assertion DOES NOT fails.<br>
</div><div>This means that memory scan does not reveals this context as it should be.<br><br></div><div>(maybe because it stops at the object which located before location of thisContext)?<br></div></div></div></div></div>
</blockquote><div><br></div><div>That would make sense. For debugging, why don't you record the objects visited in an OrderedCollection, and then you can look at what order the pointer finder found them.</div><div> </div>
</div></div></div></blockquote><div><br></div><div>well, if you look at algorithm:<br><br> pointers := IdentitySet new.<br> object := self someObject.<br> [ object == pointers ] whileFalse: [<br> 1 to: objects size do: [ :i | ((object pointsTo: (objects at: i)) and: [ (object pointsOnlyWeaklyTo: (objects at: i)) not]) ifTrue: [ pointers add: object ] ].<br>
object := object nextObject ].<br><br></div><div>since the 'pointers' is the last object created on heap, and the subject context<br></div><div>must exist before entering this method, it should eventually find it..<br>
but as it appears it doesn't..<br><br></div><div>what i thinking, that maybe i should change the stop condition to<br></div><div>[ object == 0 ]<br></div><div>(which primitive returns when there is no more object on heap),<br>
</div><div>like that i can be sure that i will visit every heap-allocated object..<br></div><div>But that is tricky because then loop may never stop if there is new object(s) created (like in #add: ) in loop body.. :(<br>
</div><div><br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<div><div><div><div></div><div><br></div><div>any suggestions/comments/ideas , how to make sure that assert will never fail?<br></div></div></div></div></div></blockquote><div><br></div><div>Doesn't that depend on how you've implemented CommonRootsFinder?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr"><div><div><div><div>
<br></div><div>-- <br>Best regards,<br>Igor Stasenko.
</div></div></div></div></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>
<br></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Igor Stasenko.
</div></div>