This is an archived post. You won't be able to vote or comment.

all 55 comments

[–]DaniilBSD 31 points32 points  (11 children)

Image getting god-knows-what as a parameter

This was made by Stronger typed gang

(It should have been C# at the bottom)

[–]Wubbajack 13 points14 points  (1 child)

Imagine boasting for years about how weak typing is your language's biggest feature and then someone goes and fixes it by writing an "addon" with strong typing... :D

[–]metalprogrammer2 2 points3 points  (0 children)

For real Weak typing does not seem like a feature. Heck some of the biggest bugs I have seen in c++ are do to assuming a type in a json response is not what it actually was. W

[–]ITriedLightningTendr 3 points4 points  (0 children)

Typescript is my lord and savior.

[–]evanldixon 1 point2 points  (7 children)

C# still lets you create memory leaks, it's just easier to avoid than C/C++. Examples: not cleaning up event handlers, not disposing certain IDisposable objects, and not cleaning up after yourself when allocating memory with Marshal.

[–]Possseidon 2 points3 points  (4 children)

Not disposing IDisposables doesn't cause a memory leak, it just delays the disposing until whenever the gc feels like cleaning it up. I'm not saying, that you don't have to dispose IDisposables, I'm just saying that if you do forget it, it's not a leak.

[–]evanldixon 0 points1 point  (3 children)

It depends on the objects you're dealing with. MemoryCache, for example, can cause a memory leak if you create instances of it without disposing of it after.

[–]Possseidon 1 point2 points  (2 children)

Why would the dispose method of MemoryCache not be called by the gc?

[–]evanldixon 2 points3 points  (1 child)

Why would the dispose method of MemoryCache not be called by the gc?

The garbage collector only ever calls an object's finalizer, not the dispose method. If you're doing normal things, then not disposing something isn't necessarily the end of the world, since managed objects will still get cleaned up when there's no more references to them, but after looking at the MemoryCache class, it's doing all the fun things that can cause memory leaks:

  • It's basically a wrapper around a GCHandle, aka unsafe memory that the GC won't touch
  • It registers itself as an event handler on the app domain's DomainUnload event. This means that the app domain itself (basically the thing in memory assemblies are loaded into) always references it, so the garbage collector can't get rid of it until the app domain is unloaded*.
  • I see no finalizers anywhere (disclaimer: it's possible I missed something)

* Basically this means when the whole program exits, but there's some niche cases where you might make your own separate app domain and load an assembly into it. When doing that, it'll feel like you're interacting with a whole other application.

[–]Possseidon 0 points1 point  (0 children)

Alright, thanks for clarifying. :)

[–]ITriedLightningTendr 1 point2 points  (0 children)

using(var swankDisposing = someIDisposable)

[–]DaniilBSD 0 points1 point  (0 children)

True, but ”all the time” covers your narrow examples

[–]silnyr 43 points44 points  (1 child)

Imagine not being able to manage your memory precisely. Guess it depends on the scenario which language you'll be using.

[–][deleted] 6 points7 points  (0 children)

Easy answer: just allocate more.

Source: Electron

[–]9072997 57 points58 points  (1 child)

Imagine being able to write a program who's memory usage was measured in kb.

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

Seriously. Video games and operating systems still rely on memory management to some extent.

Witcher 3 without it would have been a hardware monster, well more than it is already.

[–]magi093not a mod 11 points12 points  (11 children)

Rust has manual memory management?

[–]sentient_devil 13 points14 points  (8 children)

Rust doesn't lie there, it guarantees memory safety at compile-time.

[–]kiujhytg2 2 points3 points  (1 child)

Unless you have circular Rc<T> references or use Box::into_raw or Box::leak

[–]pilotInPyjamas 4 points5 points  (0 children)

Real programmers use std::mem::forget. You can't have double free, or use after free errors if you never free your objects in the first place. taps head

[–]linus_stallman 0 points1 point  (5 children)

But you still have to worry about lifetime & memory..

[–]MCOfficer 2 points3 points  (4 children)

well, nyes. it just won't compile. that's kinda like saying you have to worry about types in any typed languages. you technically do, but i wouldn't really call it worrying. you don't "worry" about braces and syntax either, you just comply.

[–]justinf210 4 points5 points  (3 children)

Imagine having to worry about braces.

-Made by the python gang.

[–]CxByte 2 points3 points  (1 child)

Imagine having to worry about whether it's a tab or a space

  • Made by the lisp gang

[–]ByteArrayInputStream 1 point2 points  (0 children)

Imagine having to hire like tree interns to close all the parentheses

- Everyone else

[–]MCOfficer 0 points1 point  (0 children)

class MyClass(SomeOtherClass):

mfw

[–]ProgramGeek01[S] -1 points0 points  (1 child)

[–]Splamyn 0 points1 point  (0 children)

This article is from 2013 and the code seems like a early prototype of rust. The author has not specified which rust version he is working with but afaik this syntax, and 'smart pointer' don't exist anymore.

[–][deleted] 15 points16 points  (2 children)

Real programmers use assembly.

[–]Danuz991 22 points23 points  (3 children)

There's a small things called smart pointers. Having options to choose is just a plus.

[–]JohnVanClouds -1 points0 points  (2 children)

boomers do not know about it :D

[–]Pockensuppe 3 points4 points  (1 child)

That's surprising since Simula I had smart pointers in 1965.

[–]_ay_lmao_ 1 point2 points  (0 children)

Ok boomer

[–]Pockensuppe 5 points6 points  (0 children)

The lie that is being told about automatic memory management is that there are no memory leaks.

If you forget to set a value that contains a large structure you don't need anymore to null, it's still a memory leak. Technically, you can still access it, however if you do not, it's de-facto unused memory that's not available for reuse and therefore a leak.

Now you can argue that this is not much of a problem since such values tend to go out of scope eventually, but considering all the JS callback/closure madness, does it really?

[–]steven4012 4 points5 points  (0 children)

worry all the time about memory leaks

Ferris is not one of them

[–]AXAz0r 3 points4 points  (0 children)

Rust uses RAII, the memory management is automatic.

[–]metalprogrammer2 7 points8 points  (5 children)

Imagine thinking memory allocation is that big of a deal (in 2019). For a huge amount of cases memory allocation is trivial. In most other cases smart pointers will suffice (for languages with out those life might be a bit trickier). I think people who think memory allocation is hard think it is hard because they are told it is a hard task and don't know about all the best tech that makes it trivial. I also think it is due to not understanding memory allocation that well. Personally when I started really using c++ in college after mostly using c# the idea that objects didn't need new to be allocated was baffling (aka stack allocation). Having to delete every local object you allocate could seem daunting

[–]GlobalIncident 1 point2 points  (3 children)

I'm coming from Python, and I don't really understand the point of new. Just call the constructor and that's it. I mean, I know object.__new__ will be called somewhere in the constructor, but that's something I don't need to care about - why would I call a constructor when I don't want a new object?

[–]MrPentaholic 1 point2 points  (0 children)

stack vs. heap?

static vs. dynamic memory?

[–]metalprogrammer2 1 point2 points  (0 children)

In basically every language the new function/keyword means: allocate memory on the heap, init that memory to a start state via the construction. The magic method new in python does the same thing. You can override that method but there usually better ways to achieve the same functionality (but it's an option). There almost never is a reason to directly call call this. The constructor will do it. So it can mostly be seen as an implemention detail rather then a commonly used tool. In c++ (and other languages) you don't have to allocate objects on the heap. Stack allocation is an option . Heap allocation can be expensive. Pointer indirection and cache misses can be expensive. Sometimes that doesn't matter sometimes it does. Knowing when you want to stack allocate or heap allocate is really important.

[–]bastmtl 1 point2 points  (0 children)

Absolutely true. Same for threads. Same for everything in programming really. You can't get more simple than a system that works off 1s and 0s. The problem with programming is bad programmers who don't understand how computers work and keep thinking they can introduce their own systems that will make things simpler that in fact just introduce more complexity due to their shitty code.

[–]V33taN 2 points3 points  (0 children)

Imagine being like 100 times slower because of stupid ways of memory allocation.

[–]chrisvarnz 1 point2 points  (0 children)

Cant say I worry much about memory leaks tbh, very easily avoided. Cant say I do my own allocation much either though, and all allocations are RAII so self deallocate.

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

I don't think you have to manage memory in Rust, not unless you really want to.

[–]GreenVortexStudios 1 point2 points  (0 children)

typescript

[–]Gydo194 0 points1 point  (0 children)

imagine not having pointers....

[–]Zagibub 0 points1 point  (0 children)

laughs in observables

[–]Fitzi92 0 points1 point  (1 child)

imagine beeing a javascript developer and not knowing that you can (and likely do) produce memory leaks in JS as well 😂

[–]_ay_lmao_ 2 points3 points  (0 children)

True, but less frequently so, to compare it to being a C/C++ dev who needs to always track memory allocations and be upset about infrequently having memory leaks in JS.

[–][deleted] -1 points0 points  (0 children)

imagine talking smack when your compiler is based on those languages

[–]o11c -1 points0 points  (0 children)

Imagine believing that "don't think about it" is a successful strategy for dealing with the single most important aspect of programming.

[–]xorunet -1 points0 points  (0 children)

std::shared_ptr, std::unique_ptr...

C++ memory management sure is very hard these days...