16:55 Can someone explain to me why is it better to create a new instance of Details class than changing its properties values? Won't that result on worse GC pressure?
Yes, you're right. If you allocate (new Class()) an object and then remove all references to it in your code, then the GC will take some CPU time to clean it up. The benefits of doing this anyway are: - Maintainability, you know it won't change while you use said objects. Meaning, fewer if-statements to verify data correctness. - In parallel processing, you can assign a group of these read-only objects to each thread without worry of race conditions. - Caching, because data won't change you don't need to deal with things like PropertyChanged events to invalidate the cache. If you're writing real-time code which run continuously without user input (i.e. sensor readers, (physics) simulations, games) then you should reduce (continuous) allocations as they can quickly pile up and degrade performance.
"Treat Warnings as errors" is the equivalent of getting your entire team of developers to stop smoking at the same time.
16:55 Can someone explain to me why is it better to create a new instance of Details class than changing its properties values?
Won't that result on worse GC pressure?
Yes, you're right. If you allocate (new Class()) an object and then remove all references to it in your code, then the GC will take some CPU time to clean it up.
The benefits of doing this anyway are:
- Maintainability, you know it won't change while you use said objects. Meaning, fewer if-statements to verify data correctness.
- In parallel processing, you can assign a group of these read-only objects to each thread without worry of race conditions.
- Caching, because data won't change you don't need to deal with things like PropertyChanged events to invalidate the cache.
If you're writing real-time code which run continuously without user input (i.e. sensor readers, (physics) simulations, games) then you should reduce (continuous) allocations as they can quickly pile up and degrade performance.
restored chrome..
Steam open