You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works on 1.8.7 and doesn't on 1.8.6. Sinatra essentially does this for caching, so it just keeps missing and re-storing, and the hash builds up with duplicate entries.
Here's a reworked Tile::Cache#fetch that makes the test pass. It's not pretty, might be a bit verbose, but it seems to work.
def fetch(*key)
cached_template = nil
if RUBY_VERSION == '1.8.6'
@cache.keys.each do |k|
if k == key
@cache[k] ||= yield
cached_template = @cache[k]
end
end
if cached_template.nil?
@cache[key] = yield
cached_template = @cache[key]
end
else
@cache[key] ||= yield
cached_template = @cache[key]
end
cached_template
end
I think 1.8.6 is not a priority any longer, with Rack having dropped support (and Rails/Rubygems going to). Also, this is a well known Ruby bug, not a Sinatra bug.
I had a better description of this, but it was on the old Lighthouse which is now closed.
Sinatra 1.0 leaks memory when the cache is enabled on 1.8.6 due to the hash within array bug, eventually eating all the memory on the system.
Example:
This works on 1.8.7 and doesn't on 1.8.6. Sinatra essentially does this for caching, so it just keeps missing and re-storing, and the hash builds up with duplicate entries.
Here's a reworked Tile::Cache#fetch that makes the test pass. It's not pretty, might be a bit verbose, but it seems to work.
Finally, here is a test for reproduction: http://github.com/kyledrake/tilt/commit/76672520040c4e4501f85a83194d7dcc562ff2dd
The text was updated successfully, but these errors were encountered: