I have a custom inspector script which manipulates a SerializedProperty array. What I noticed is that when I use DeleteArrayElementAtIndex it doesn’t actually delete an item but leaves a null at a specified index.
I added a second check which is triggered during the next Layout event which looks for null values and does the same DeleteArrayElementAtIndex on the first one. And this time array actually shrinks.
Another solution is to assign a value of null to objectReferenceValue prior to deleting it. This has the advantage of not deleting multiple elements if Unity decide to fix this issue in the future:
// Unity doesn't remove element when it contains an object reference.
var elementProperty = arrayProperty.GetArrayElementAtIndex(i);
if (elementProperty.objectReferenceValue != null)
elementProperty.objectReferenceValue = null;
arrayProperty.DeleteArrayElementAtIndex(i);