enable memory-checks only on special flag, not general debug
(cherry picked from commit 23382e9c8a78bc21e2adb97f785c18da00db12b0)