Hacker News new | ask | show | jobs
by amluto 1315 days ago
I haven't actually played with this, but if the same pattern of lazily (sloppily?) returning arbitrary pointers along with errors continues, the lifetime ought to be extended arbitrarily. The caller could itself return val, err, and so on up the chain.
1 comments

I'm not seeing how that would cause a memory leak. It just means that the value might be GCed a bit later. Could you give an example?
It’s a temporary leak. My point is that it’s an actual side effect, unlike how in C it has no effect whatsoever if the value is ignored.

In a language where destruction of an object often releases external resources (C++, for example, or Python or Rust to a lesser extent), this effect would be more dramatic. Imagine someone doing this in Python:

    def func():
      f = tmpfile(…)
      err = do something
      return f, err
This style would be absurd and wrong — it keeps f alive to long.