Add method to count memory used