Bpy.data.materials.users doesn't behave like it used to

In slightly older versions of blender, the following code can be used to clean up materials that are not assigned to any object:

for mat in bpy.data.materials:
    if mat.users == 0:
        bpy.data.materials.remove(mat)

Now bpy.data.materials.users returns the total number of objects the material has ever been assigned to, meaning the above code no longer works.
Is this a bug in blender or is there a new way I should be getting the number of objects that have a certain material assigned to them?

what version of Blender are you using? do you have an example .blend we can see? Testing all of the versions I have on this machine, and users returns the number of active users (+1 if the material is using the fake_user flag)

I am using Blender 3.0 from steam.