@@ -4465,35 +4465,31 @@ base class FragmentProgram extends NativeFieldWrapperClass1 {
44654465 // the same encoding here so that users can load assets with the same
44664466 // key they have written in the pubspec.
44674467 final String encodedKey = Uri (path: Uri .encodeFull (assetKey)).path;
4468- final FragmentProgram ? program = _shaderRegistry[encodedKey]? .target ;
4468+ final FragmentProgram ? program = _shaderRegistry[encodedKey];
44694469 if (program != null ) {
44704470 return Future <FragmentProgram >.value (program);
44714471 }
44724472 return Future <FragmentProgram >.microtask (() {
44734473 final FragmentProgram program = FragmentProgram ._fromAsset (encodedKey);
4474- _shaderRegistry[encodedKey] = WeakReference < FragmentProgram >( program) ;
4474+ _shaderRegistry[encodedKey] = program;
44754475 return program;
44764476 });
44774477 }
44784478
44794479 // This is a cache of shaders that have been loaded by
4480- // FragmentProgram.fromAsset. It holds weak references to the FragmentPrograms
4481- // so that the case where an in-use program is requested again can be fast,
4482- // but programs that are no longer referenced are not retained because of the
4483- // cache.
4484- static final Map <String , WeakReference <FragmentProgram >> _shaderRegistry =
4485- < String , WeakReference <FragmentProgram >> {};
4480+ // FragmentProgram.fromAsset. It holds a strong reference to theFragmentPrograms
4481+ // The native engine will retain the resources associated with this shader
4482+ // program (PSO variants) until shutdown, so maintaining a strong reference
4483+ // here ensures we do not perform extra work if the dart object is continually
4484+ // re-initialized.
4485+ static final Map <String , FragmentProgram > _shaderRegistry =
4486+ < String , FragmentProgram > {};
44864487
44874488 static void _reinitializeShader (String assetKey) {
44884489 // If a shader for the asset isn't already registered, then there's no
44894490 // need to reinitialize it. The new shader will be loaded and initialized
44904491 // the next time the program access it.
4491- final WeakReference <FragmentProgram >? programRef = _shaderRegistry[assetKey];
4492- if (programRef == null ) {
4493- return ;
4494- }
4495-
4496- final FragmentProgram ? program = programRef.target;
4492+ final FragmentProgram ? program = _shaderRegistry[assetKey];
44974493 if (program == null ) {
44984494 return ;
44994495 }
0 commit comments