Doesn't there already similar method? I expect that counting memory should be done on another place already