Flutter Http high CPU usage

116 views Asked by At

I tried to send a GET request:

Future<void> testHttp() async {
  final response = await http.Request("GET", Uri.parse(url)).send();
  print('testHttp response:${response.statusCode} ');
}

@override
Widget build(BuildContext context) {
  return ElevatedButton(
    onPressed: testHttp,
    child: const Text("Send"),
  );
}

The url points to a file download address, but I ignore the response. And then it cause CPU(i3-9100f) high usage abidingly, unless I read the stream in response.

CPU High usage

Looking at DevTool found that garbage collection has been triggered.

enter image description here

Does this response need to be turned off manually? But I can't find anything like close() on response. Or is this a bug?

0

There are 0 answers