It’s not a bug as it’s documented - https://docs.blender.org/api/current/bpy.types.Depsgraph.html#bpy.types.Depsgraph.object_instances
object_intstances - All object instances to display or render (Warning: Only use this as an iterator, never as a sequence, and do not keep any references to its items)
So make sure you get everything you want from the object instance during the loop and don’t access it (or it’s attributes, such as matrix_world
) outside the loop, otherwise you’ll get this kind of errors or Blender might even crash.
Example you attached is using a list just to get it’s length, it never accesses list elements, therefore no issues.