[swift-dev] How does a standard collection know when its storage has to die?

Slava Pestov spestov at apple.com
Wed Oct 25 17:47:29 CDT 2017


These types are essentially single-field structs. The underlying storage is referenced from this field, which has a reference type. While structs cannot have user-defined destructors, the compiler knows when a value of struct type goes out of scope and destroys its fields, which for reference types decrements their reference count.

Slava

> On Oct 25, 2017, at 3:29 PM, Daryle Walker via swift-dev <swift-dev at swift.org> wrote:
> 
> OK, so the standard collections (Array, Set, Dictionary) are value types with remote storage. Since they don’t have de-initializers, how would any reference count get any notification to eventually de-allocate ? Or is the memory leaked? Or is some sort of secret system-provided de-initalizer added?
> 
> Just thinking of a undiscriminated union idea and wondering how to prevent this kind of leak. 
> 
> Sent from my iPhone
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev



More information about the swift-dev mailing list