Jump to content

PSA: When people say stuff about "memory leaks", this is what it means.


kenbobo

Recommended Posts

I'm not fond of youtube.

But C# is one huge memory leak as it is; letting a subsystem manage your memory in a complex application causes problems as you, the programmer, are smarter than any subsystem. C# will only deallocate memory when all references to an object have been removed. If you have a "C# Pointer" hanging around somewhere (C#, by necessity, does have pointers; in fact everything except base types should be pointers now) the object will remain in memory forever.

Now let's talk about cross-referencing, which two classes refer to each other. You try to "delete" both classes by setting their pointers to null, but they cross-reference, and what is more have references to objects still in play. These type of classes, like singletons (self-referencing), can easily be by designer choice; and if the objects include a static member you can still manipulate them later on. It can get even messier if there are further objects in these classes which make a large self-referencing chain of headache. Makes you wish for simple automagical deletion and fixing the crashes with a strong IDE.

So say it with me! C# Bad, Garbage Collection Memory Management Bad, Assembly Good!

Edited by Fel
Link to comment
Share on other sites

I'm not fond of youtube.

But C# is one huge memory leak as it is; letting a subsystem manage your memory in a complex application causes problems as you, the programmer, are smarter than any subsystem. C# will only deallocate memory when all references to an object have been removed. If you have a "C# Pointer" hanging around somewhere (C#, by necessity, does have pointers; in fact everything except base types should be pointers now) the object will remain in memory forever.

Now let's talk about cross-referencing, which two classes refer to each other. You try to "delete" both classes by setting their pointers to null, but they cross-reference, and what is more have references to objects still in play. These type of classes, like singletons (self-referencing), can easily be by designer choice; and if the objects include a static member you can still manipulate them later on.

So say it with me! C# Bad, Garbage Collection Memory Management Bad, Assembly Good!

Classes are not objects. Maybe stick to PERL. You can do a lot of damage in Assembly if you're sloppy.

Link to comment
Share on other sites

Classes are not objects. Maybe stick to PERL. You can do a lot of damage in Assembly if you're sloppy.

Semantics.

Wait a minute. Did I read that wrong or is Fel praising assembler coding for it's garbage collection and memory management?

It's a joke, I'm shaming C# because it is a "modern language." People expect GC and self-managing memory, despite the problems that arise from the use of those. Even with C++ people are going to be passing more off to the GC than doing themselves, even if doing it themselves can create routes of optimization that leads to better performance.

Basically, the only way to escape the problems of modern programming is to escape modern programming all together.

Edited by Fel
Link to comment
Share on other sites

Classes are not objects? Well, yes. But, as Fel points out, they can be.

http://stackoverflow.com/questions/1425093/can-a-class-return-an-object-of-itself

Yes, you can do a lot of damage in Assembly if you're sloppy. Then again, you can equally do a lot of damage in C as well, as has happened time and time again ... likely with greater frequency considering the ever grown popularity of C languages.

Use and Abuse of Garbage Collected Languages

There's an old saying: If you want it done right, do it yourself.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...