First of all, memory leaks are when you create something dynamically, and you don't free the memory that it uses.
C++ doesn't have memory leaks. C++ does allow programmers to create them though:
1 2 3 4 5 6 7 8 9
|
int main (void)
{
int x = 4;
int n = x;
int* p = new int[n]; //create an array of integers dynamically
//don't have anymore code, but we need to delete the array to prevent memory leaks!
delete[] p;
}
|
If you were to run that code several times, the OS should properly free the memory. However, if you don't include the delete[] line, it creates a leak because that memory is still allocated and it isn't available to any other program. Too many of those leaks, and it can make your computer really slow. Unless your program uses dynamic allocation, you shouldn't need to worry about memory leaks.
Java has no such thing because it uses a garbage collector. When a variable is no longer needed, the memory for it is automatically freed, making it available to other programs.
However, there are garbage collectors available for C++. Your friend probably has no idea that garbage collectors can be used with C++, and that is why he recommended Java. He wasn't wrong, but he wasn't completely correct either.
Infinite decimals should be handled by your hardware and the operating system already. You don't need to worry about that too much.
The problem you are dealing with is rounding error. Try using double instead of float. That may fix your problem.