5 ms·
The article says that const pointers can't release their memory, so that would lead to memory leaks. (Obviously in some cases you might want to keep that const
by irishsultan 7y ago
The article says that const pointers can't release their memory, so that would lead to memory leaks. (Obviously in some cases you might want to keep that const pointer until the program is finished, but it's not a generic solution to the "I want a pointer that can't be mutated" because often you do want to drop the value at some point)
- twic 7y agoThat's a very good point! I was coming from a Rust mindset, where ownership and mutability are somewhat separated. Although you can't own an object through an immutable reference, you can own one through an immutable binding. But i am slowly learning that D's model is sufficiently different that there isn't a useful comparison here.