[Rubycocoa-devel 1387] Re: object_id when fetching from NSArray

Zurück zum Archiv-Index

Allison Newman demal****@mac*****
Fri Apr 24 19:51:42 JST 2009


 OK, I've been digging a bit more, and I came up with this comment in _ocid_to_rbobj

    // We don't cache CF-based objects because we don't have yet a reliable
    // way to remove them from the cache.

So, all CF-based objects have a new ruby proxy object generated for them each time they pass from obj-c land into ruby land.  But each time this is done, the ruby object has the same ocid, so it still accesses the same obj-c instance each time...



On Thursday, April 23, 2009, at 11:44PM, "Brian Marick" <maric****@examp*****> wrote:
>Suppose you have an NSArray containing some Objective-C objects. I  
>understand why the following can be false:
>
>array[0] == array[0]
>
>Each time the element is extracted from the array, it could get a new  
>"ruby half". The main point of this note is to confirm that's correct  
>behavior.
>
>The lesser part of the note: I don't understand why the behavior isn't  
>consistent. Consider this program:
>
>#! /usr/bin/env ruby
>require 'osx/cocoa'
>include OSX
>
>def run(klass, count)
>  array = make_array(klass, count)
>  first = collect_the_object_ids(array)
>  second = collect_the_object_ids(array)
>  if first == second
>    puts "success"
>  else
>    puts "FAILURE for #{klass.name}"
>    puts first[0,10].inspect
>    puts second[0,10].inspect
>  end
>end
>
>def make_array(klass, count)
>  (0...count).collect {
>    klass.alloc.init
>  }.to_ns
>end
>
>def collect_the_object_ids(array)
>  array.collect { | e | e.object_id }.to_ruby
>end
>
>
>run(NSDictionary, 1)
>run(NSString, 1)
>run(NSTextField, 100000)
>
>
>It consistently produces these results:
>
>FAILURE for OSX::NSDictionary
>[3079050]
>[3078130]
>FAILURE for OSX::NSString
>[3077490]
>[3077260]
>success
>
>An NSManagedObject in a 16 element NSArray had a stable object_id the  
>first 17 times it was extracted, then it changed.
>
>There's caching going on in some cases. What are the rules behind  
>them? Thanks.
>
>-----
>Brian Marick, independent consultant
>Mostly on agile methods with a testing slant
>www.exampler.com, www.exampler.com/blog, www.twitter.com/marick
>
>_______________________________________________
>Rubycocoa-devel mailing list
>Rubyc****@lists*****
>http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel
>
>




More information about the Rubycocoa-devel mailing list
Zurück zum Archiv-Index