Last active
January 9, 2022 16:07
-
-
Save kranfix/d7625a4abf9b5ece934879609cb53c4f to your computer and use it in GitHub Desktop.
const memory optimization in Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final obj1 = MyComplexObject(1, 2.0); | |
final obj2 = MyComplexObject(1, 2.0); | |
assert(!identical(obj1, obj2)); // obj1 and obj2 are not the same object | |
const cobj1 = MyComplexObject(1, 2.0); | |
const cobj2 = MyComplexObject(1, 2.0); | |
assert(identical(cobj1, cobj2)); // cobj1 and cobj2 are the same object | |
assert(!identical(cobj1, obj1)); // cobj1 and obj1 are not the same object | |
} | |
class MyComplexObject { | |
const MyComplexObject(this.a, this.b); | |
final int a; | |
final double b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment