Home > Mobile >  Do Navigator pushNamed & pushReplacementNamed create zombie routes in memory?
Do Navigator pushNamed & pushReplacementNamed create zombie routes in memory?

Time:08-10

Route A and Route B with buttons that can send to the other route when tapped (Route A with a button, Route B with a button on the bottombar).

Route A --uses Navigator.pushNamed() to send to--> Route B.

Route B --uses Navigator.pushReplacementNamed() to send to--> Route A.

And so on. Imagine to tap to obtain a loop.

Page A initState() is called multiple times but Page A dispose() is never called.

Does it mean that the memory is filling up of zombie Page A instances?

CodePudding user response:

this is what i understand.

when you pushReplacementNamed to new route, navigator will remove current route and based on documentation said

The returned route will be pushed into the navigator.

eg: we are from A to B .

  • current Navigator is [ A, B ].

then we pushReplacementNamed to A, so it only replace route B from navigator and return all route before B (if exist) to current navigator.

  • current Navigator is [ A, A]

then if you pushNamed from A again ,

  • then the Navigator will be [ A, A ,B].

yes its not disposed.

  • Related