LoadDef loads resource if it was not loaded yet and set it's reference counting to 1. If resource was already loaded by other code, it's reference counter is simply increased by one. When some code does not need resource anymore, it call Dereference method, which decrease reference counter by one. When it reaches zero, the resource is freed.
So image we have some structure like AdvMapObject with Def field = 0. On the first draw call, LoadDef will be called for each such object with particular def name. If we have 10 objects on the map of the same type, the def will have reference counter = 10.
SN:R intercepts calls to LoadDef and changes one def name to another. But if def pointer is already stored in some structure, we cannot force that structure user to use new def. When all objects are removed from map (reference counter decreased until 0 and def is freed), SN:R is able to take effect on the next LoadDef call.