Skip to content
Discussion options

You must be logged in to vote

Does this mean when our string object goes out of scope and we have our GC disabled, will it trigger string:destroy() for us?

Only if you use <close> annotation on its declaration, that is, a string will be destroyed automatically only if you declare it with <close> annotation.

For example, the bellow will not leak memory:

## pragmas.nogc = true -- disable the GC
require 'string'

local function f()
  local s: string <close> = string.upper('hello')
  -- <close> will call destroy for us at the end of this scope, collecting string memory for us
end

f()

This will also not leak memory:

## pragmas.nogc = true -- disable the GC
require 'string'

local function f()
  local s: string = string.…

Replies: 5 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@stefanos82
Comment options

Answer selected by edubart
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@edubart
Comment options

@stefanos82
Comment options

Comment options

You must be logged in to vote
2 replies
@edubart
Comment options

@stefanos82
Comment options

Comment options

You must be logged in to vote
2 replies
@edubart
Comment options

@stefanos82
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants