All basic Symbian OS related errors and also API related errors cause a leave in the interface code. For example, an out of memory situation causes a leave but also an invalid contact ID. The imerror.h lists all the errors.
IM API does not consume memory significantly after creating the object. However the memory used is dependent on the size of the instant messages sent and received.