When to free memory in C

Поделиться
HTML-код
  • Опубликовано: 4 сен 2019
  • This issue has cropped up many times where beginnners were confused as to why we use free in certain situations and why we don't. Hopefully, this video helps clarify the problem.
    Check out our Discord server: / discord

Комментарии • 15

  • @NippyWolf
    @NippyWolf 2 года назад +6

    You just managed to explain to me in less than 15 minutes more than my professor ever succeed to explain to me in 3 hours. Thank you so much! you're awesome

  • @alef485
    @alef485 28 дней назад

    thank you so much for the video, this channel is going to be a constant visit point on my cs career path

  • @secondaccount5196
    @secondaccount5196 3 года назад +3

    This answers 100000 dev people's questions.

  • @kaamilmirza6963
    @kaamilmirza6963 3 года назад +4

    You are a wonderful person

  • @siddireddyvignesh
    @siddireddyvignesh Год назад

    Thank you sir for delivering this valuable information
    Hope u deliver more

  • @alvarohigino
    @alvarohigino 11 месяцев назад

    I think I jumped something in my studies, I didn't learn about these different kind of memories and I'm now in memory allocation. 😂

    • @CodeVault
      @CodeVault  11 месяцев назад +1

      In school (especially in high school) few are taught about these differences. Only later on after students have used it do they learn about it (if ever)
      I was very confused when my programming teacher told me to use free() on some pointer without explaining anything

  • @warplanner8852
    @warplanner8852 2 года назад +1

    This is because p and q are stack variables pointing to a "clump" of _heap_ memory malloc'ed, right? So that when the function (here, the main() function - hence, the program) goes out of scope, its stack variables are destroyed or dealloc'ed.

    • @CodeVault
      @CodeVault  2 года назад

      Yes. Those stack variables are deallocated but the malloc-ed clump of memory isn't, thus you get a memory leak

  • @kevinzebb
    @kevinzebb 4 месяца назад

    Caught me off guard, m-alloc?

    • @CodeVault
      @CodeVault  4 месяца назад

      It comes from "memory allocation"... so, m-alloc seems right to me. Especially since there is calloc which sounds wrong if pronounced as a full word. Pronounce however you'd like

  • @angel_machariel
    @angel_machariel 2 года назад

    This does not work for CodeBlocks, right? It appears this only works in VS. Correct?

    • @CodeVault
      @CodeVault  2 года назад +2

      Yes this is only compatible with the Visual C++ compiler. There are alternatives like valgrind for gcc

    • @angel_machariel
      @angel_machariel 2 года назад

      @@CodeVault Oh I'll try that. Thanks!

  • @paladin80lvl
    @paladin80lvl 2 года назад

    are you linus tolvars?