What is a "terminated object", and why can't I call methods on it?
Asked Answered
B

2

6

Periodically I get this exception:

NotImplementedError: method `at' called on terminated object

on this line of code:

next if Hpricot(html).at('a')

What does this error mean? How can I avoid it?

Burnie answered 13/1, 2011 at 6:41 Comment(2)
Does it also happen if you assign the result of Hpricot(html) to a variable before whole loop instead of performing it every time?Sclerosis
html is the loop parameter, so I can't do it before the loop, though I could do something like doc = Hpricot(html) at the top of the loop and do doc.at('a'). I'll give this a tryBurnie
J
2

The library you are using makes use of a custom C extension. In the C extension, it is trying to call a method on a Ruby object which has already been garbage-collected.

This can't happen in pure Ruby, because the garbage collector will only free objects which are no longer accessible from any reference. But in C, it is possible to have a reference remaining to a Ruby object, in a place which the garbage collector doesn't check (for example, the compiler may have put a variable in a CPU register).

Jezabelle answered 14/5, 2014 at 19:56 Comment(0)
H
0

It might be a linking problem. Check that you didn't link the extension twice.

Howund answered 27/6, 2011 at 13:28 Comment(1)
By "link the extension twice", do you mean "require the extension twice"? (Isn't require designed to make sure this doesn't cause problems?)Burnie

© 2022 - 2024 — McMap. All rights reserved.