Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

AssemblyScript: GC finalizer for Response #50

@radu-matei

Description

@radu-matei

AssemblyScript/assemblyscript#1256 introduced a new GC hook that runs before managed objects before being collected.
This is helpful for Response objects, whose handles have to be manually closed right now, and in theory, we could remove this requirement by implementing the finalizer.

The issue is that Response objects don't seem to be collected - i.e. the console log is never executed here.

@global function __finalize(ptr: usize): void {
    // @ts-ignore
    if (__instanceof(ptr, idof<Response>())) {
        Console.log("running finalizer with ptr: " + ptr.toString())
        // change type to `Response` and call `close`
    }

// @ts-ignore
__collect();

Manually keeping track of Response objects and the collected pointers, it's clear that they are not collected with the current implementation, which could be an indicator that we are actually leaking memory.

Another question is related to manually calling __collect - without manually calling it, the finalizer hook is not always executed. Are there any best practices around manually calling it or not?

cc @jedisct1

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions