The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Snapshots in Wee and Cyclic Weak References

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Neumann

Posts: 66
Nickname: backflash
Registered: May, 2003

Michael Neumann is fallen in Love with Ruby
Snapshots in Wee and Cyclic Weak References Posted: Nov 16, 2004 9:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Michael Neumann.
Original Post: Snapshots in Wee and Cyclic Weak References
Feed Title: Mike's Weblog
Feed URL: http://www.ntecs.de/blog-old/index.rss?cat=ruby&count=7
Feed Description: Blogging about Ruby and other interesting stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Michael Neumann
Latest Posts From Mike's Weblog

Advertisement
There's a problem with objects registered for backtracking whose snapshots have a reference back to the registered object itself.

Let's look at some scenarios. I'll call the object to register "obj" and it's snapshot "snap". I further assume that "snap" references "obj".

Scenario 1 (Good)

  1. We register "obj" for backtracking.
  2. "obj" goes out of scope -> it gets garbage collected.
  3. We take a snapshot. No snapshot of "obj" is taken.

Here, no problem.

Scenario 2 (Worse)

  1. We register "obj" for backtracking.
  2. We take a snapshot "snap".
  3. Snapshot "snap" goes out of scope.
  4. Now "obj" could go out of scope, too.

Note that as long as a snapshot of "obj" exists, "obj" cannot go out of scope.

Scenario 3 (Worst)

  1. We register "obj" for backtracking.
  2. We take a snapshot "snap".
  3. Before "snap" goes out of scope, we take another snapshot. This new snapshot also includes "obj".

As long as at least one snapshot exists that was taken after the initial "snap" snapshot, "obj" will not be garbage collected. It's included in every further snapshot.

This might happen in Wee as we store a fixed number of snapshots (there's always one available). So you have to take care to not introduce a reference back to the registered object from the snapshot.

Solutions

  • Whenever possible, avoid to register objects in dynamically created components (e.g. MessageBox).
  • The snapshot of a registered object which is taken by calling method take_snapshot of the objects's class should never contain a reference back to the referenced object. If this happens, you'll introduce memory-leaks (for the duration of the session).

Read: Snapshots in Wee and Cyclic Weak References

Topic: No tightly coupling with DBMs in Active Record Previous Topic   Next Topic Topic: Another day in the world-conversion business

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use