code: def calculate_object_size(obj: typing.Any, unit: str = "byte") -> int:
      """Iteratively calculates the `obj` size in bytes.
  
      Visits all the elements related to obj accounting for their respective
      sizes.
  
      Parameters
      ----------
      obj
          Object to evaluate.
      unit
          The unit in which the accounted value is going to be returned.
          Values: 'byte', 'kB', 'MB' (Default: 'byte').
  
      Returns
      -------
      The size of the object and its related properties and objects, in 'unit'.
  
      """
      seen = set()
      to_visit: collections.deque = collections.deque()
      byte_size = 0
  
      to_visit.append(obj)
  
      while True:
          try:
              obj = to_visit.popleft()
          except IndexError:
              break
  
          # If element was already covered, skip it
          if id(obj) in seen:
              continue
  
          # Update size accounting
          byte_size += sys.getsizeof(obj)
  
          # Mark element as seen
          seen.add(id(obj))
  
          # Add keys and values for size account
          if isinstance(obj, dict):
              for v in obj.values():
                  to_visit.append(v)
  
              for k in obj.keys():
                  to_visit.append(k)
          elif hasattr(obj, "__dict__"):
              to_visit.append(obj.__dict__)
          elif hasattr(obj, "__iter__") and not (
              isinstance(obj, str)
              or isinstance(obj, bytes)
              or isinstance(obj, bytearray)
          ):
              for i in obj:
                  to_visit.append(i)
  
      if unit == "kB":
          final_size = byte_size / 1024
      elif unit == "MB":
          final_size = byte_size / (2**20)
      else:
          final_size = byte_size
  
      return int(final_size)
  
imports: from __future__ import annotations
  import collections
  import copy
  import dataclasses
  import functools
  import math
  import sys
  import typing
  from river.base.typing import FeatureName
  from river.stats import Cov, Var
label_desc: Use image node_id 2 for calling a global function with example usage: calculate_object_size(obj, unit) and returns: int