From: Axel M. R. <rub...@ro...> - 2008-11-24 14:36:39
|
Excerpt: It seems the implementation of string.to_ns is not correct for some strings or situations, and to_nsstring works better. Explanation: I have come upon a problem which has been bugging me for days. I've written a small code example, and that works perfectly, but my main code keeps crashing. Let me explain. I have some code which has worked for months, but after the result text got bigger, suddenly stopped working. I've put a lot of debug output in it: # replaceText is a new, highly recursive function ftext = replaceText(self.mainText,loopStack) puts "Finished substitutions on Template" p ftext.class p ftext.length joepie= ftext.to_ns p joepie.class p joepie.length self.mainText = joepie This program doesn't convert the ruby string to NSString, but instead returns nil. The output of this is: Finished substitutions on Template String 43334 NilClass 2008-11-23 23:40:01.301 Telan[8971:10b] TLAppController#genereerPlanning: NoMethodError: undefined method `length' for nil:NilClass As I explained, my small code example works flawlessly with strings up till 1000000 chars, so that wasn't the problem. Maybe it's a memory problem? After some more head scratching, I noticed another to_ns method: to_nsstring, now deprecated. However, this method works fine! ftext = replaceText(self.mainText,loopStack) puts "Finished substitutions on Template" p ftext.class p ftext.length joepie= ftext.to_nsstring p joepie.class p joepie.length self.mainText = joepie The output of this is (correctly): Finished substitutions on Template String 43334 /Users/axel/Develop/svn/telan/TelanRuby/build/Debug/Telan.app/Contents/Resources/TLRTFParse.rb:120:in `replaceTemplate': to_nsstring is now deprecated and its use is discouraged, please use to_ns instead. OSX::NSCFString 43333 "TLRTFParse entering observeValueForKeyPath mainText" So, it seems the method implementation of string.to_ns is different from string.to_nsstring, but the method of to_nsstring is less buggy than the newer to_ns. I am not a ruby wizard, and have no idea how to solve this problem correctly. As I assume a memory issue, is there a way to 'flush' the ruby garbage collector, as you would do with NSAutoreleasePools? Or is there a way to trace into the ruby interpreter to see where the to_ns method fails? Anyone here on the list who can help me investigate and debug this thing? thanks Axel -- _________________________ Axel Roest axelloroestello@{AIM/MSN} - Skype:axellofono - XOIP: 084-8749988 |