You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lazy_static crate offers a way to define a global "static" variable following the execution of a piece of code that is supposed to instantiate a value, as opposed to "constant" variables that don't allow this. The static declared in this way is thread-safe and lasts as much as the entire program; however, when the program ends, the destructor is not called automatically (this feature is not supported by rust), causing a memory leak.
Use static and lazy_static would be the best solution for us, because there is no way to directly instantiate the values we need as constants. Is the memory leak acceptable here ?
If not, there could be other solutions:
Use thread_local that has the same functionality of lazy_static except that the scope of the static variable will be only the thread in which it is defined, so in multi-threaded applications we will have the same duplicated static variable for each thread, but the destructor of the variable is run when the program ends;
Wrap the constant we need in another struct, and carry this struct around (like a Context), and free it when we don't need it anymore;
Using functions that return the constant when it's needed, and drop it immediately after.
The text was updated successfully, but these errors were encountered:
lazy_static crate offers a way to define a global "static" variable following the execution of a piece of code that is supposed to instantiate a value, as opposed to "constant" variables that don't allow this. The static declared in this way is thread-safe and lasts as much as the entire program; however, when the program ends, the destructor is not called automatically (this feature is not supported by rust), causing a memory leak.
Use static and lazy_static would be the best solution for us, because there is no way to directly instantiate the values we need as constants. Is the memory leak acceptable here ?
If not, there could be other solutions:
The text was updated successfully, but these errors were encountered: