get_referrers_recursive#

ivy.get_referrers_recursive(item, *, depth=0, max_depth=None, seen_set=None, local_set=None)[source]#

Recursively retrieve referrers for an object.

This function recursively fetches referrers for the specified item up to a given max_depth.

Parameters:
  • item (object) – The object for which referrers should be retrieved.

  • depth (int, default: 0) – Current depth in the recursion. (default is 0)

  • max_depth (Optional[int], default: None) – Maximum depth of recursion. If None, there’s no depth limit. (default is None)

  • seen_set (Optional[set], default: None) – Set of seen referrer IDs to prevent duplicates. (default is None)

  • local_set (Optional[set], default: None) – Set of local referrer IDs to avoid redundancy. (default is None)

Return type:

Container

Returns:

ret – A container representing referrers and their sub-referrers, respecting the max_depth.

Examples

>>> import gc
>>> example_function = lambda: (obj := [1, 2, 3]) and ivy.get_referrers_recursive(obj, max_depth=2)
>>> result = example_function()
>>> print(result)
{repr:[1,2,3]}