← Back to context

Comment by Sesse__

6 months ago

> "Forget RAII" would have made more sense.

For memory only, which is one of the simplest kinds of resource. What about file descriptors? Graphics objects? Locks? RAII can keep track of all of those. (So does refcounting, too, but tracing GC usually not.)

You deal with those the same way you deal with them in any language without RAII, some sort of try-with-resource block or defer.

Not making a value judgment if that is better or worse than RAII, just pointing out that resources of different kinds don't have to be handled by the same mechanism. This blog post is about memory management in C3. Other resource management is already handled by defer.

  • Why would you treat the two differently, though? What benefit does it bring? (defer is such an ugly, manual solution in general; it becomes very cumbersome once you may want to give control of the resource to anyone else.)

    • Well, the answer is obvious in garbage collected languages: because a GC excels at managing memory but sucks at managing other resources.

      Here, the answer is that ownership semantics are disliked by the language designer (doesn't fit the design goals), so they're not in the language.

      3 replies →