✅ Why is the attempted fix still creating a new copy of the dv each time CallDispose is called?
12 Replies
it's a struct, a value type. Changing its data (_disposedYet) doesn't update the existing one,
dv
, it makes a new one with the new values
which admittedly doesn't sound like it makes much sense when the struct is changing its own values, but I don't think structs typically have any logic in them, assumedly for that reason
I'm not sure I explained that accurately but the point is just that the dv
you have a reference to is not the DisposableValue that has _disposedYet = true. Basically, use a class imo, or maybe dig into how structs work and maybe if you ref it into CallDispose you can make it workI get it
I went from boxing to getting a new copy of the value
thanks @D.Mentia
tbh I don't get it :lul: like if it's creating a new DisposableValue when you set _disposedYet... which instance is that method running on, the old one or new one?
A new one is created on each function call
like if you did
would it print false?
In the commented out top one you get a new box with a new copy of the value, in the attempted fix you get a copy of just the value without a box
So then... when exactly is the copy created? When it first enters the Dispose() method, it doesn't know that a value is going to be changed... so it must be entering it on the original instance
But then upon the value being changed, it creates a new instance, and then continues method execution from within that new instance apparently? IDK, weird
value types are pass-by-copy
Oh I see, got it. Even when not changing a value
Yeah
you've answered my question, I'll mark this thread as resolved :lul:
we both learned something