Skip to content

gc:arc destroys the global variable accidentally. #13691

Closed
@khchen

Description

@khchen

Compile with --gc:arc.

Example

type Variable = ref object
  value: int

proc `=destroy`(self: var type(Variable()[])) =
  echo "destroying variable"

proc newVariable(value: int): Variable =
    result = Variable()
    result.value = value

proc test(count: int) =
  var v {.global.} = newVariable(10)

  var count = count - 1
  if count == 0: return

  test(count)
  echo "destroyed: ", v.isNil

test(3)

Current Output

destroying variable
destroyed: true
destroyed: true

Expected Output

destroyed: false
destroyed: false

Additional Information

  • It was working without --gc:arc
$ nim -v
Nim Compiler Version 1.1.1 [Windows: amd64]
Compiled at 2020-03-19
Copyright (c) 2006-2019 by Andreas Rumpf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions