Cyclic Marshals :: again the need for a built in creation parent method

okay, after way too many hours i was finally able to Marshal my objects and
overcome the cyclic references that caused a spiraling depth problem.
unfortunately it is not a general purpose solution. i could not figure a way
to do that. rather i created two methods, a #pre_dump methods that nil’d out
the specific cyclic references in my objects before the #Marshal.dump and a
#post_load method that restores them after the #Marshal.load.

thes whole of this problem stems from the common need to store the creation
parent of an object:

class ParentObject
	def method_x
		c = ChildObject.new(self)
	end
end

def ChildObject
	def initialize(parent)
		@parent = parent
	end
end

i have talked about this before. this is fairly common occurance. i have heard
it argued that it is better to have it explicitly defined like this, but
among many other things, Marshalling is another example in which having a
built in method (#creator perhaps) akin to #self would be of great use simply
because the creation parent would not have to be stored in an instance
variable and thus no cyclic reference would arise.

-transami

Hi,

···

In message “Cyclic Marshals :: again the need for a built in creation parent method” on 03/01/04, Tom Sawyer transami@transami.net writes:

okay, after way too many hours i was finally able to Marshal my objects and
overcome the cyclic references that caused a spiraling depth problem.
unfortunately it is not a general purpose solution. i could not figure a way
to do that. rather i created two methods, a #pre_dump methods that nil’d out
the specific cyclic references in my objects before the #Marshal.dump and a
#post_load method that restores them after the #Marshal.load.

Hmm, marshal should handle cyclic references. Could you show us the
example program that cause you a problem?

						matz.

matz,

well, i’ll be damned, you are right. on your cue i went to recause the
problem. but i was able to remove the post and pre methods and it still
works! i do not know what originally caused marshal to spiral out of control,
but it is now gone. i’m not sure what i changed that effected it so. the
program is rather complex so it is hard to say. i will keep my eye out for
any reoccurance, though, and i will isolate it and let you know if it
reappears.

thanks,
-transami

···

On Saturday 04 January 2003 12:08 am, Yukihiro Matsumoto wrote:

Hi,

In message “Cyclic Marshals :: again the need for a built in creation > parent method” > > on 03/01/04, Tom Sawyer transami@transami.net writes:

okay, after way too many hours i was finally able to Marshal my objects
and overcome the cyclic references that caused a spiraling depth problem.
unfortunately it is not a general purpose solution. i could not figure a
way to do that. rather i created two methods, a #pre_dump methods that
nil’d out the specific cyclic references in my objects before the
#Marshal.dump and a #post_load method that restores them after the
#Marshal.load.

Hmm, marshal should handle cyclic references. Could you show us the
example program that cause you a problem?

  					matz.