New Reply

prevent memory leakage from coding

 
Share Thread Thread Tools
Apr5-13, 04:44 AM   #18
 

prevent memory leakage from coding


I am very grateful!
Many thanks to ScottSalley!!!
Your explanation I printed and hung at the computer!
Apr21-13, 07:37 PM   #19
 
What I do to avoid memory leaks is use .NET. It is really pretty difficult to crash a machine using the .NET libraries, and it has very good performance. It is also available for Linux. I did program extensively in C for many years, and my belief is, no matter how "good" you are, how "good" your tools are, and how "good" your design is, if you use C or C++ and program directly in the OS's libraries, you WILL sooner or later get a memory leak, and it may take you a long time to realize it.

Alternatively, you could use Java--or any strongly typed, modern language besides C or C++.
Apr22-13, 07:30 AM   #20
 
Thanks for the advice. But even in Java garbage collector does not solve the problem with memory leaks completely.
Apr22-13, 10:24 AM   #21
 
Recognitions:
Homework Helper Homework Help
.NET mostly solves the issue of defragging memory when there is is a lot of allocation and freeing of memory, which can create a fragmentation problem even if there are no memory leaks. It does this by occaionally pausing the application and defragging (repacking) memory.
Apr22-13, 12:39 PM   #22
 
Quote by JulsSmile View Post
Thanks for the advice. But even in Java garbage collector does not solve the problem with memory leaks completely.
I don't understand this statement. As far as I know, the JVM and the .NET framework do not have memory leaks at all.
Apr22-13, 03:51 PM   #23
 
Quote by rcgldr View Post
.NET mostly solves the issue of defragging memory when there is is a lot of allocation and freeing of memory, which can create a fragmentation problem even if there are no memory leaks. It does this by occaionally pausing the application and defragging (repacking) memory.
.NET periodically releases unused memory via a special thread that runs in the background, which is imperceptible to the application--the program does not pause. .NET's garbage collector runs only very rarely, and only if an application runs out of memory (in which case, the application actually stops running until the garbage collector completes its task, which can introduce a noticeable pause).
Apr23-13, 05:11 AM   #24
 
Quote by harborsparrow View Post
I don't understand this statement. As far as I know, the JVM and the .NET framework do not have memory leaks at all.
It's not a very simple question. There are not memory leaks in C + + understanding. Memory leaks in Java have a slightly different mechanism of occurrence, that's what hi meant
Apr23-13, 06:27 AM   #25
 
Quote by harborsparrow View Post
What I do to avoid memory leaks is use .NET. [...] if you use C or C++ and program directly in the OS's libraries, you WILL sooner or later get a memory leak, and it may take you a long time to realize it.
But isn't that comparing apples with oranges?
Application layer development with close to the OS programming?

Even when I use boost or MPI libs from C++ I don't mess around with sockets, buffers, mallocs and stuff manually, but rely on the robustness of lower layers for those needs.

As you rely on the coding done by MS folks when you use .NET, don't you?
Apr23-13, 08:34 AM   #26
 
Quote by Solkar View Post
Even when I use boost or MPI libs from C++ I don't mess around with sockets, buffers, mallocs and stuff manually, but rely on the robustness of lower layers for those needs.

As you rely on the coding done by MS folks when you use .NET, don't you?
.NET libraries have undergone use and testing by millions of people by the time I get hold of them, so they have pretty much had any bugs ironed out. Of course, Microsoft libraries could have bugs in them, but it's in the interest of Microsoft to make these things stable, and they are quite good at that at this point.

If you use a language such as Java or C# (or any .NET language) that runs on a framework, it will be less likely to crash, firstly because the languages themselves are strongly typed and take care of allocation and reclaiming automatically with well-tested strategies, and secondly because each process runs in a protected environment such that a poorly-behaved process is not allowed to crash the machine. Also, these languages are just-in-time compiled, which means that once they "warm up" (once most of the code has executed at least once), they are running as native code and run about as fast as C or C++ programs. This is why these languages are so popular and successful, especially for use on web servers. Safety and good behavior sharing a machine.

There are times when you need to code down to the metal, and then, and ONLY THEN, would I choose to use C or C++ directly.
Apr23-13, 11:19 AM   #27
 
Quote by harborsparrow View Post
If you use a language such as Java or C# (or any .NET language) that runs on a framework, it will be less likely to crash, firstly because the languages themselves are strongly typed and take care of allocation and reclaiming automatically with well-tested strategies, and secondly because each process runs in a protected environment such that a poorly-behaved process is not allowed to crash the machine.
Spooky... why the heck do I feel like in a SUN, IBM or MS sales event of about year 2000 when I read this?

In fact it's ages ago that I've seen a C/C++/Fortran binary of mine crashing a machine.
Sometimes they overheat a node, which is shut down then, but that's a cooling, not a coding issue.

Quote by harborsparrow View Post
Also, these languages are just-in-time compiled, which means that once they "warm up" (once most of the code has executed at least once), they are running as native code and run about as fast as C or C++ programs.
This is somewhat amusing - on one hand there's this magic that protects the app and the OS whenever required, and, foremost, the universe from coders of doom.
On the other hand it seems to magically disappear when it comes to performance issues.

For about 20 years yet, I've read about Java either that
- its bad performance is simply not existent and my profiling plainly wrong. Period.
- Or that the very version will fix exactly that (whatever) issue.
New Reply
Thread Tools


Similar Threads for: prevent memory leakage from coding
Thread Forum Replies
How do memory metals (Shape-memory alloys) work? Biology, Chemistry & Other Homework 0
What's the difference between short term memory and working memory? Biology 2
Muscle memory or normal memory? General Discussion 1
How to let the cold work shape memory alloy to acquire shape memory properties Materials & Chemical Engineering 2
Verbal memory/semantic memory, also long-term memory Social Sciences 0