Closed benjamin-hodgson closed 1 year ago
I should add that the properties in the Resources
class do already load the resources lazily, but they're all evaluated in References
's static constructor. So it's work-around-able (use the Resources
directly and call CreateFromImage
manually), but would be good to fix in the library if possible.
Today, the various properties on
References
are declared as get-only properties with an initialiser. Example:There's also a static
All
property which stores all of the otherPortableExecutableReference
s in an array.All of these initialisers always run (when the
References
class is first accessed), so all of the embedded resources are always loaded, even if you only need to use one of them. It looks like the resources total around 50MB (which is retained until the process terminates, since they are static fields), but also on the Desktop Framework there's additional garbage generated by thestream.CopyTo
call inGetResourceBlob
.Would you be open to loading the resources lazily so that we only pay for what we use?
This could be changed to use
System.Lazy
if you want to be certain to load the resource once only (thread safety). Would you accept a pull request containing a change like this?