Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the memory address of a Flutter / Dart variable? Is this possible?

I would like to print the current memory address of a variable in Dart but I don't know if this is possible. I want to write a code to show all memory address in a liked list structure.

Advice are welcome.

like image 983
Rave Code Avatar asked Jan 13 '20 14:01

Rave Code


People also ask

How to see memory usage Flutter?

User and Flutter EventExpand the events at the bottom of the hover card to display all events for that timestamp. Displayed below the events pane is the memory chart and the Android memory chart. The android-memory chart is specific to an Android app, and it shows Android ADB meminfo from an ADB app summary.


2 Answers

There is no way to print the memory address of a variable in Dart.

Even if you could print the memory address, there is nothing meaningful that you could do with it.

If you want to identify objects, you could use identityHashCode.

like image 88
jamesdlin Avatar answered Sep 20 '22 08:09

jamesdlin


It's not possible to access raw memory of Dart objects. Dart is a garbage collected language which means that Dart objects are not guaranteed to live at a particular memory address as the garbage collector can (and certainly will) move these objects to different memory locations during a garbage collection. Within the Dart virtual machine Dart objects are almost exclusively accessed and passed around via handles and not raw pointers for this very reason.

like image 35
Ben Konyi Avatar answered Sep 23 '22 08:09

Ben Konyi