-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectp: android_alarm_managerThe Android background execution pluginThe Android background execution pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specifically
Description
The following code will end up creating an ever-increasing amount of threads:
void alarmServiceHandler() {
final DateTime now = DateTime.now();
final int isolateId = Isolate.current.hashCode;
print("[$now] alarmServiceHandler isolate=${isolateId} function='$alarmServiceHandler'");
AndroidAlarmManager.initialize().then((bool ready) {
print("AndroidAlarmManager");
if (ready) {
print("AndroidAlarmManager.oneShot");
final int alarmID = 1;
AndroidAlarmManager.oneShot(const Duration(seconds: 1), alarmID, alarmServiceHandler, exact: true);
}
});
print("[$now] alarmServiceHandler FINISH");
}
void main() {
AndroidAlarmManager.initialize().then((bool ready) {
print("AndroidAlarmManager");
if (ready) {
print("AndroidAlarmManager.oneShot");
final int alarmID = 1;
AndroidAlarmManager.oneShot(const Duration(seconds: 1), alarmID, alarmServiceHandler, exact: true);
}
});
runApp(MyApp());
}After execution of the function and new oneShot alarm is registered, I'd expect the thread to finish and get freed but that doesn't seem to happen. Note that the Isolate hash stays the same, but a new thread is created each time oneShot is called (and never released).
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectp: android_alarm_managerThe Android background execution pluginThe Android background execution pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specifically