This is the 11th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021

Obtaining memory Information

Memory acquisition mainly includes obtaining VM memory information, application memory information, and class object memory information.

Vm memory information and memory information of class objects can be obtained through VM_service, but cannot be obtained temporarily in release mode.

To obtain the overall memory information of the application, you need to call the plug-in using native methods.

Obtaining Exception Information

Classification of Flutter anomalies

The categories are as follows:

1. The App

A. The synchronization is abnormal

B. Asynchronous exceptions

2. The Framework is abnormal

3. Other exceptions

Abnormal APP

App exception is generally an exception that occurs in the code written by ourselves. If not handled, the following code will not be executed.

In general, synchronous exceptions can be caught by try-catch and asynchronous exceptions can be caught by Future catchError.

Flutter also provides a centralized way to manage App anomalies, the zone.runZoned method.

APP Exception catching

Using the zone.runZoned method, you can trap all APP exceptions by wrapping runApp

 runZoned<Future<Null>>(() async {
 }, onError: (error, stackTrace) async {
  //Do sth for error
Copy the code
void main() { FlutterError.onError = (FlutterErrorDetails details) { //Do sth for error }; . }Copy the code
Fluttererror. onError = (FlutterErrorDetails details) Async {// Forward an exception to the Zone Zone.current.handleUncaughtError(details.exception, details.stack); };Copy the code
 Isolate.current.addErrorListener(new RawReceivePort((dynamic pair) {
   var isolateError = pair as List<dynamic>;
   var _error = isolateError.first;
   var _stackTrace = isolateError.last;
   Zone.current.handleUncaughtError(_error, _stackTrace);
Copy the code

The current uncaught exceptions can be retrieved using the addErrorListener method of the ISOLATE. Similarly, we use the Zone’s handleUncaughtError method to transfer exceptions to the zone for centralized processing.

Other exception catching

In Dart language, all Dart codes run in some ISOLATE, which is an independent worker similar to threads but not sharing memory, and an independent Dart program execution environment. In fact, the default environment is a main ISOLATE. There is no more information about the use of THE ISOLATE than the fact that the ISOLATE provides a way to catch all uncaught exceptions in the current ISOLATE.

Other exceptions

The exception can be forwarded through the handleUncaughtError method provided by the Zone.

The above exception was processed in zone.runZoned.

Looking at the source code, we know to set the custom error handling callback by setting FlutterError. OnError

Framework Exception Catching

Generally, the code written by yourself causes the code inside the Flutter Framework to be abnormal. By default, the exception page will be displayed to display the exception information.