add memory monitor to minimize memory use.