admin管理员组文章数量:1301491
I'm figuring out whether my app has memory leak.
So I run flutter app on profile mode, not debug mode and see Memory tab.
This is the Profile Memory tab when I launch my app right away.
It's the just one example case.
You can see SignUpScreen
has 5 instances and MainNavigationScreen
has 14 instances.
But as seeing my code, when app launches it directs to SplashScreen
.
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return const SplashScreen();
},
),
GoRoute(
path: '/p/:sendUserId',
builder: (context, state) {
final sendUserId = state.pathParameters["sendUserId"];
return PartnerAgreementScreen(sendUserId: sendUserId);
},
),
],
);
@override
void initState() {
super.initState();
_initializeNavigator();
}
@override
void dispose() {
super.dispose();
}
Future<UserProfile?> _initializeUserProfile() async {
final userProfile =
await ref.read(userProvider.notifier).fetchLoggedUserInfo();
return userProfile;
}
Future<void> _initializeNavigator() async {
try {
final userProfile = await _initializeUserProfile();
if (initialLoginState.value && userProfile != null) {
await Future.wait([
_intializeUserIdPrefs(),
_initializeAppVersion(),
_initializeFcmToken(),
_initializeInvitationCode(),
_initializeFontSize(),
]);
if (!mounted) return;
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const MainNavigationScreen(tab: "일기"),
),
// (route) => false,
);
} else {
Future.delayed(const Duration(seconds: 1), () {
if (!mounted) return;
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const SignUpScreen(),
),
// (route) => false,
);
});
}
} catch (e) {
// ignore: avoid_print
print("_initializeNavigator -> $e");
Future.delayed(const Duration(seconds: 1), () {
if (!mounted) return;
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (_) => const SignUpScreen(),
),
(route) => false,
);
});
}
}
And SplashScreen redirects user to MainNavigationScreen
or SignUpscreen
.
In this case that user is logged in, it will directs user to MainNavigationScreen
, not SignUpScreen
.
I double check that it directs to 'MainNavigationScreen' only once and not 'SignUpScreen'.
But why does memory has 14 instances of MainNavigationScreen and 5 SignUpScreen?
And even DiaryModel
that will be used in another Screen has also 2 instances, etc.
本文标签:
版权声明:本文标题:Uncalled class has multiple instances at app launch in flutter App analyzing profile memory tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741677911a2391993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论