Calling "global.__collect()"?


#1

I’ve seen several threads and issues (ex1, ex2, and ex3) referencing the command “global.__collect()” as a means to manually run the garbage collector on iOS, but when I try using it in my Angular projects, I get the error “Property ‘__collect()’ does not exist on type ‘Global’.” Has anyone else experienced this?

For reference, I am attempting to run this code:

public collectGarbage() {
  if (isIOS) {
    global.__collect(); // this line raises the error
  }
}

#2

@lin-brian-l It’s just the TypeScript definition, you can do something like

(<any>global).__collect();

But a more convenient / cross platform way will be

import { GC } from "utils/utils";

GC();

#3

Oops, I was under the impression that GC() was an Android-specific function. Thanks for your help as always, @manojdcoder!