Merge "Fix memory leak with layers. This fix bug http://b/2394813 This is a two-parts CL (needs C++ modifs)"