Product SiteDocumentation Site

3.8. Memory management

Obviously you don’t have to worry about memory management yourself. The python bindings will correctly release MAPI objects when their reference count in python reaches 0. Internal referencing inside MAPI allows for reverse-order releases:
folder = store.OpenEntry(None, None, 0)
message = folder.CreateMessage(0)

folder = None
message = None
Although the folder is released first, the fact that another message object was opened on it before prevents the actual MAPI object from being freed. Once all its children have been freed, the top-level object will free any resources used.