Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

hpricot

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?

like image 700
Tom Lehman Avatar asked Jan 13 '11 06:01

Tom Lehman


1 Answers

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).

like image 158
Alex D Avatar answered Nov 11 '22 18:11

Alex D