garbage collection - Weak Tables in lua - What are the practical uses? -
i understand weak tables are.
i'd know weak tables can used practically?
the docs say
weak tables used in situations wish annotate values without altering them.
i don't understand that. mean?
posted answer comments...
since lua doesn't know consider garbage, won't collect isn't sure garbage. in situations (one of debugging) want specify value variable without causing considered "not trash" lua. understanding, weak tables allow you'd variables/objects/etc, if they're weak referenced (or in weak table), still considered garbage lua , collected when garbage collection function called.
example: think if wanted use associative array, key/value pairs in 2 separate private tables. if wanted use key table 1 specific use, once done using it, locked existence in lua. if use weak table, however, you'd able collect garbage done using it, freeing resources using.
to explain 1 cryptic sentence annotating, when "alter" variable, lock existence , lua no longer considers garbage. "annotate" variable means give name, number, or other value. so, means you're allowed give variable name/value without locking existence (so lua can garbage collect it).
translation:
weak tables used in situations wish give name value without locking value existence, takes memory.
Comments
Post a Comment