Sure. But Java's (also used in C#, Go, Python, Javascript and many other modern programming languages) solution, namely Garbage Collection (GC) introduces a non-negligible overhead.
For things like scripting languages, frontend applications, GC is an excellent trade-off because the added security trumps the performance loss. But for use cases that require raw performance, GC doesn't cut it, so C and C++ are still widely used to build operating systems, device drivers, and web browsers (which must run web applications with acceptable performance).
Rust is, I think, the first programming language that started to change this status quo, because even with its memory safeguards (which are not like Garbage Collection at all), Rust can compete with C and C++ on performance.