After modifying the sample to show the referrers:
import gc
gc.collect()
for i, obj in enumerate(gc.get_objects()):
t = repr(obj)
if '<NULL>' in t and isinstance(obj, tuple):
for j, ref in enumerate(gc.get_referrers(obj)):
print('ref', j, type(ref), ref, end='\n\n')
print('refs', j, 'total')
print(i, t)
# crash print('...', obj[0])
print(i, 'total')
import sys
print(sys.version)
The shortened Console output with Python 3.5.1 in Pythonista v. 3.1 (301016) is the following:
ref 0 <class 'list'> [{'__init__': <slot wrapper '__init__' of 'object' objects>, ..., ..., <frame object at 0x1099183e8>] <<< very long list shortened <<<
ref 1 <class 'tuple'> (7595, (<NULL>,))
ref 2 <class 'dict'> {'i': 7595, 'j': 2, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x109969710>, '__cached__': None, '__spec__': None, 'obj': (<NULL>,), '__file__': '/private/var/mobile/Containers/Shared/AppGroup/A45067AD-96C3-483D-9A6E-F33AA6C0CBA5/Pythonista3/Documents/nullcrash.py', '__name__': '__main__', '__doc__': None, 'r': {...}, 't': '(<NULL>,)', '__builtins__': <module 'builtins' (built-in)>, 'gc': <module 'gc' (built-in)>}
refs 2 total
7595 (<NULL>,)
7602 total
3.5.1 (default, Sep 20 2016, 14:05:14)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]