Added memory check when consuming a message.

The consumer will be stopped if the available memory is not enough.

Fixed memory calcul.