The lifespan of a memory foam and latex layer in a mattress can vary depending on several factors such as quality of materials, usage, and care. Generally, high-quality memory foam and latex layers can last for several years ( in actuality latex lasts way longer).
However, it's not possible to say that one will last longer than the other as it can depend on the specific materials and manufacturer ( I have never seen a mattress with at least two inches of latex not last satisfactorly until the end of it's warranty period while memory foam obviously degrades it's ability to support in just a few years). To ensure the longest lifespan, it's important to follow the manufacturer's care instructions and use a suitable mattress protector. ( care instructions meaning the mattress should be rotated head to toe at least twice a year ( A mattress cover does not extend the life of a mattress but it does stop fluids from seaping through if it is waterproof).