Now it has access to information it needs and it's clear who is reponsible for memory management. Fixes #11039.