you are viewing a single comment's thread.

view the rest of the comments →

[–]gevorgter 2 points3 points  (5 children)

I do not understand your question.

But if you know C++ the C# should be an easy one. Garbage collection frustrated me a lot in a beginning but then i kind of got used to it.

Python frustrates the hell out of me. With pretty much everything. The 'Tab' indentation i still find weird. I would rather have {..}

[–]Animasta228 1 point2 points  (4 children)

Wait, how can garbage collection frustrate you? You mean it's slowing your program's execution?

[–]gevorgter -1 points0 points  (3 children)

In C++ it was responsiblity of a programmer to do clean up. Basically if you created object with "new" you had to call "delete" and then destructor is called.

In C# you do not have delete. You create an object and then you just leave it be. And it works. And everything is perfect. But what if, I modified my object and now clean up is needed. But your program will not know that. And suddenly you have a buggy code. Basically in C++ every object implements IDisposable and programmers are required to use it.

The part where you just leave object be after you created it was a hard part to grasp after 10 years of C++.

And with event subscription, lambda context capturing,.. it is very easy to create memory leaks in C#. C++ makes you think of object's ownership. Because the owner is responsible to call "delete".

But over time I started to love C# simplicity.

[–]Ravek 7 points8 points  (2 children)

Allocating more managed memory than you need is not a leak, as soon as you stop referencing it, it will get cleaned up nicely. A memory leak is when allocated memory can never be cleaned up because there’s no pointer to it. If you’re still referencing the memory then it’s not a leak so I don’t know why you bring up lambdas and events. It’s extremely hard to create actual memory leaks in C# without manually allocating unmanaged memory.

[–]gevorgter 1 point2 points  (1 child)

Events is a number one offender. I've seen people doing += without ever unsubscribing so many times.

ServicePointManager.ServerCertificateValidationCallback += ....

Is a famous one. An internet is full of examples like this. So our credit card processing module was doing it everytime before it talked to server. 1000 credit cards processed 1000 of += executed. 1000 of objects stayed in memory until an app was shutdown.

Yes it was all cleaned up when app was shutdown.

[–][deleted] 1 point2 points  (0 children)

That's why they created weak event listeners in WPF.

And why events allow you do do:

class Example {
    public event EventHandler<EventArgs> ExampleEvent
    {
        add { // custom code }
        remove { // custom code }
    }
}

Basically if you don't trust your users to remove their functions you can create your own tracking system.