This code compiles with default gc and with --gc:arc:
type
Language* = ref object
impl*: pointer
proc gBoxedFreePangoLanguage*(self: Language) =
discard
proc languageFromString*(): Language =
var l: Language
new(result)
new(result, gBoxedFreePangoLanguage)
Run
$ nim c --gc:arc t6.nim
Hint: 20040 LOC; 0.129 sec; 19.73MiB peakmem; Debug build; proj:
/tmp/hhh/t6.nim; out: /tmp/hhh/t6 [SuccessX]
Run
But this code does only compile with default gc:
type
Language* = ref object
impl*: pointer
proc gBoxedFreePangoLanguage*(self: Language) =
discard
proc languageFromString*(): Language =
new(result)
proc getSampleLanguage*(): Language =
new(result, gBoxedFreePangoLanguage)
Run
$ nim c t4.nim
Hint: used config file '/home/stefan/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/stefan/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: t4 [Processing]
Hint: gcc -o /tmp/hhh/t4
/tmp/stefan/.cache/nim/t4_d/stdlib_system.nim.c.o
/tmp/stefan/.cache/nim/t4_d/@mt4.nim.c.o -ldl [Link]
Hint: 22196 LOC; 0.153 sec; 19.762MiB peakmem; Debug build; proj:
/tmp/hhh/t4.nim; out: /tmp/hhh/t4 [SuccessX]
Run
$ nim c --gc:arc t4.nim
Hint: used config file '/home/stefan/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/stefan/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: t4 [Processing]
/tmp/hhh/t4.nim(12, 6) Error: cannot bind another '=destroy' to:
Language:ObjectType; previous declaration was constructed here implicitly:
/tmp/hhh/t4.nim(9, 6)
Run
For me that was and still is confusing, I would prefer the last not compiling
case, because in the other cases the finalizer can be called unintentionally.