I'm not a Ruby Guru by any means, but my guess is no, given that the String literal "password" creates an object, and pass << "password" creates another. pass = nil kills neither -- rather, it reassigns pass to *point* to the nil object (and pass falls immediately out of scope, any how), leaving the other two at the mercy of the GC. Maybe there's something you can do with the ObjectSpace?

I dunno.. this sounds like a wild goose chase to me, especially since the user of this lib is going to have to do the same thing which whatever temporary objects he creates while processing the password.. This is something that'd be very easy to do in C.. Is it Ruby's intention to be the best at everything?

> Would something like the following be an improvement, do you think?
> 
> #!/usr/local/bin/ruby -w
> 
> def fetch_password
>      pass = ""
>      pass << "password"
>      pass
> ensure
>      pass = nil
> end
> 
> p fetch_password    # => "password"
> 
> __END__
> 
> James Edward Gray II