Skip to content

Minimal runtime GC collects pinned objects. #1646

Closed
@forcepusher

Description

@forcepusher

UPDATE: See the short version of the repro.
However this one might still be useful because it has to pass the test.

Repro: MinimalGCBugRepro.zip
Steps to reproduce:

  1. npm run asbuild:incremental then npm test.
  2. Observe the expected repeating trace 123456.
  3. npm run asbuild:minimal then npm test.
  4. Observe the unexpected traces with random numbers.

Reproduction overview:

export class SomeClass {
  public someArray: StaticArray<SomeNestedClass>;

  public constructor() {
    this.someArray = new StaticArray<SomeNestedClass>(1);
    this.someArray[0] = new SomeNestedClass();
  }

  public growArray(): void {
    const resizedArray = new StaticArray<SomeNestedClass>(this.someArray.length * 2);
    memory.copy(changetype<usize>(resizedArray), changetype<usize>(this.someArray),
      offsetof<SomeNestedClass>() * this.someArray.length);
    this.someArray = resizedArray;
  }

  public outputFirstArrayElement(): void {
    trace(this.someArray[0].someField.toString());
  }
}

class SomeNestedClass {
  public someField: i32 = 123456;
}
const myModule = require("..");

const someClass = new myModule.SomeClass();
myModule.__pin(someClass);
someClass.growArray();
someClass.outputFirstArrayElement();
myModule.__collect();
someClass.growArray();
someClass.outputFirstArrayElement();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions