Skip to content
DevMeme
4831 of 7590
LowLevelProgramming Post #5291 · source on Telegram

When clear(m) eats more memory than the variable it should free

Description

The meme is a vertical split of two photos. On the left, an orange cat held by a human is proudly gripping a small fish in its mouth. On the right, a bright orange-and-red plush fish toy with bulging eyes has an entire white cat halfway down its maw, comically reversing the predator - prey roles. A bold white caption with black outline at the bottom right reads "CLEAR(M)", and a tiny fragment of text ")" is barely visible near the top. Technically, the image jokes about an over-zealous call to clear() or free() that wipes out far more data than intended - illustrated by the plush fish devouring the cat instead of the cat eating the fish. It resonates with low-level programmers and debuggers who have accidentally nuked memory, triggered segmentation faults, or introduced hard-to-trace bugs through improper resource deallocation

Comments

36
Anonymous ★ Top Pick Pro tip for anyone still #defining CLEAR(m): if it expands to memset(heap_base, 0, UINTPTR_MAX), don’t be surprised when the allocator shows up like a plush fish and swallows the rest of your process for dessert
  1. Anonymous ★ Top Pick

    Pro tip for anyone still #defining CLEAR(m): if it expands to memset(heap_base, 0, UINTPTR_MAX), don’t be surprised when the allocator shows up like a plush fish and swallows the rest of your process for dessert

  2. Anonymous

    After 20 years of arguing whether it should be m.clear() or clear(m), we finally compromised and made everything immutable. Now nobody's happy, but at least the function signatures are pure

  3. Anonymous

    The eternal debate: should the collection clear itself, or should we clear the collection? In OOP languages, m.clear() makes the object responsible for its own cleanup - very self-reliant. But in functional paradigms, clear(m) treats the collection as data to be operated upon. The real question is: when you call m.clear(), does the method belong to m, or does m belong to the method? This meme perfectly captures that moment when you switch languages and spend 10 minutes debugging because you wrote list.clear(m) in Python after a week of writing C's memset(m, 0, sizeof(m))

  4. Anonymous

    M.clear(): evict contents politely. clear(M): contents evict you. Mutability's revenge on sloppy APIs

  5. Anonymous

    Watching clear(m) in a hot path is feeding your p95 to an inflatable fish - reassign the map unless you don’t actually own the reference

  6. Anonymous

    m.clear() keeps capacity; CLEAR(m) keeps only regrets - never trust the all-caps macro that evaluates your argument three times

  7. @callofvoid0 3y

    which lang?

  8. @Mirolas 3y

    Explain please

    1. @callofvoid0 3y

      same concept different approach

      1. @Saeid025 3y

        I'm not sure... For example clearing a vector doesn't necessarily empty the memory space it's using

        1. @callofvoid0 3y

          yeah you right

        2. @callofvoid0 3y

          but I haven't seen the expression of this method

          1. @callofvoid0 3y

            and I don't know which lang it is

            1. @callofvoid0 3y

              but generally if the implementation of the method nullifies members it is actually freeing the memory right?

              1. @Vlasoov 3y

                not always too

            2. @RiedleroD 3y

              probably pseudocode

    2. @AlexAparnev 3y

      In python x.repr() and repr(x) is exactly the same, as also dir for example So this is definately not python Maybe joke about what we consider as main part of language: object in oop or function in procedural prog

      1. @CcxCZ 3y

        No, not exactly. In Python there are few special behaviours that you can override by methods, such as x.\_\_repr\_\_ for repr(x) or x.\_\_add\_\_ for the + operator. However in Nim x.foo(bar) is just a syntax sugar for foo(bar, x) and it actually works fairly well as you can overload for given types and this subsumes inheritance into subtyping. Edit: Telegram stubbornly interprets underscores as formatting even when there is an explicit formatting, confusing the actual meaning.

        1. @CcxCZ 3y

          Even when I wrap it in code block quotes. Sigh. I give up.

        2. @ZgGPuo8dZef58K6hxxGVj3Z2 3y

          I bet you are an iPhone user. (Because of the bugged link)

          1. @CcxCZ 3y

            Nekogram X. That happened through edits as apparently combining explicit style and inferred from the text makes it miscalculate the positions.

            1. @ZgGPuo8dZef58K6hxxGVj3Z2 3y

              iOS has had it too for a while.

        3. @RiedleroD 3y

          backslash before an underscore to escape it

          1. @CcxCZ 3y

            But that leaves the underscore there. sigh

            1. @RiedleroD 3y

              install a better tg client

              1. @CcxCZ 3y

                What FOSS options are there? I used to be on vanilla telegram-foss and them switched to nekogram x because of better layout. Perhaps desktop does this better. Also *leaves backslashes* ffs, I am sleep.

                1. @RiedleroD 3y

                  idk I use the official client

                  1. @CcxCZ 3y

                    Unfortunately they don't release the source often so telegram-foss builds tend to lag behind and nekogram is even worse at that. OTOH all the new features lately were about "premium" moneymaking nonsense and I chose not to care.

                2. @Odinmylord 3y

                  i think owlgram is pretty good and it should be FOSS

    3. @AlexAparnev 3y

      I got it Left - method inside, object outside Right - function outside object inside

  9. @Saeid025 3y

    But dropping it will

  10. @ZgGPuo8dZef58K6hxxGVj3Z2 3y

    Wait this isn’t the same or sm I misunderstanding the meme?

    1. @RiedleroD 3y

      it does the same

      1. @ZgGPuo8dZef58K6hxxGVj3Z2 3y

        Depends on implementation

        1. @RiedleroD 3y

          ig, yeah

  11. @klemaai 3y

    It thought it’s the cat’s right rear paw in its mouth

Use J and K for navigation