You can have one content handler that handles both cases, but this requires a check to see which case needs to be handled each time the parser invokes the handler.
The best way to avoid freeing memory in a handler is to flag or record the objects to be freed and have the program check from time to time whether anything is waiting to be freed.