This loop is used in barcode scanning software. It may run as many times as a barcode is scanned, which is hundreds of times in an hour.
# locpats is a list of regular expression patterns of possible depot locations
for pat in locpats:
q = re.match(pat, scannedcode)
if q:
print(q)
return True
q is a Match object. The print(q)
tells me that every match object gets its own little piece of memory. They'll add up. I have no idea to what amount in total.
I don't need the Match object anymore once inside the if
. Should I wipe it, like so?
q = re.match(pat, scannedcode)
if q:
q = None
return True
Or is there a cleaner way? Should I bother at all?
If I understand right (from this), garbage collection with gc.collect()
won't happen until a process terminates, which in my case is at the end of the day when the user is done scanning. Until that time, these objects won't be regarded as garbage, even.