Logo

Programming-Idioms

History of Idiom 209 > diff from v6 to v7

Edit summary for version 7 by steenslag:
New Ruby implementation by user [steenslag]

Version 6

2019-11-07, 14:46:17

Version 7

2019-11-25, 23:46:28

Idiom #209 Type with automatic deep deallocation

Declare a type t which contains a string s and an integer array n with variable size, and allocate a variable a of type t. Allocate v.s and v.n and set them to the values "Hello, world!" for s and [1,4,9,16,25], respectively. Deallocate v, automatically deallocating v.s and v.n (no memory leaks).

Idiom #209 Type with automatic deep deallocation

Declare a type t which contains a string s and an integer array n with variable size, and allocate a variable a of type t. Allocate v.s and v.n and set them to the values "Hello, world!" for s and [1,4,9,16,25], respectively. Deallocate v, automatically deallocating v.s and v.n (no memory leaks).

Code
T = Struct.new(:s, :n)
v = T.new("Hello, world", [1, 4, 9, 16, 25])
v = nil