Clearing a Dictionary. What's the Difference?

I’m looking to free memory. Is there any difference between these three statements?

d.Clear d = Nil d = New Dictionary

None that I’m aware of. I tend to just d = new Dictionary.

the clear removes all keys and values.
So you can reuse the dictionary.
I do use clear when I clear a cache which is implemented a dictionary.
The object stays alive.

and technically the clear keeps the object which new call allocates a new object which may take a microsecond longer.
The setting to nil causes destructor to run which may do similar to clear anyway.

In a long loop, I’d bet Clear is faster than recreating a Dictionary (btw, d = Nil is not needed in your original example code) since creating objects can be expensive, but beyond that, I’d assign a new one.

Many things likely affect which would be quicker than the other

I’d bet you’d have to run millions of iterations to tell the difference.
And also that to a point clearing could be slower if the dictionary is large.
What those tipping points are I’m not sure of

If there are many different references to the dictionary then it makes sense to clear it rather than create a new one and try to have every body who’s holding a reference to it pick up the new one. If you clear it then any references that don’t just point to the same global would remain valid too.