title: Is that necessary to set null for any class instance in dispose() of state class in flutter to avoid holding that class instance in memory?
body: <p>I am having a class instance(SampleData data) as field in the state class of my widget(SecondRoute). The class instance holds in memory while inspecting using the memory profiler. Is that necessary to set null for the instance in dispose() of state class to avoid holding that class object in memory?</p>
  <pre><code>import 'package:flutter/material.dart';
  
  void main() {
    runApp(const MyApp());
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);
  
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    const MyHomePage({Key? key, required this.title}) : super(key: key);
  
    final String title;
  
    @override
    State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    late SecondRoute secondRoute;
  
    @override
    void initState() {
      secondRoute = const SecondRoute();
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: ElevatedButton(
              child: const Text('Open route'),
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) =&gt; secondRoute),
                );
              },
            ),
          ));
    }
  
    @override
    void dispose() {
      super.dispose();
    }
  }
  
  class SecondRoute extends StatefulWidget {
    const SecondRoute({Key? key}) : super(key: key);
  
    @override
    State&lt;SecondRoute&gt; createState() =&gt; _SecondRouteState();
  }
  
  class _SecondRouteState extends State&lt;SecondRoute&gt; {
  
    SampleData? data;
    @override
    void initState() {
      data = SampleData('John', 28);
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(
            title: const Text(&quot;Second Page&quot;),
          ),
          body: Center(
            child: Column(children: &lt;Widget&gt;[
              Row(
                children: [Text(data!.name!), Text(data!.age!.toString())],
              ),          
            ]),
          ));
    }
  
    @override
    void dispose() {
      data = null;
      super.dispose();
    }
  }
  
  class SampleData {
    SampleData(this.name, this.age);
    final String? name;
    final double? age;
  }
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/2sIUi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2sIUi.png" alt="memory profilier image" /></a></p>