0

I learned about ‘free’ which is used after malloc not to make garbage memory in C. What’s recycle? I looked up for it but could not find any code. All I got is the explanation about free.. Are they the same?

To add, in my book about data structure (general linear lists) says that “Recycle is a pseudocode command to return a node’s space to dynamic memory.

Thanks a lot.

this is the diagram

I will discard the picture if there is any problem with the license.

Community
  • 1
  • 1
Alicia May
  • 43
  • 5
  • 1
    I think the "pseudocode command" "recycle" is pseudocode used in your book to summarize what the effect of free is. Can you quote a little context of the use of "recycle" ? – Yunnosch Nov 17 '17 at 06:45
  • 3
    One interpretation of "recycle" is that after a call to `free` the same memory might appear again in some future call to `malloc`. – Bo Persson Nov 17 '17 at 06:58
  • @Yunnosch I have no keyboard right now so added a diagram. Please have a look – Alicia May Nov 17 '17 at 09:20

2 Answers2

1

Recycling means freeing unused memory so that they can be used later.

If you keep on malloc-ing without free-ing, after some time of running, your program may be taking GBs of RAMs, mostly unused. Direct consequences may be the operating system's denying your program's further malloc request, or even burden down the whole system.

Recycling is not pseudo-code. It's real code telling the OS that "This block of memory is no longer used. You can allocate it to any program." After that the system can manage this specific block of memory again instead of leaving it wasted. The real code is free(), while recycling is just a term used in computer science.

It's always a good practice to free unused memory in terms of efficiency.

iBug
  • 35,554
  • 7
  • 89
  • 134
-1

I had a look at the phrase you mentioned in google books. What they have meant is that they assume that they have already defined a function or pseudocode, void recycle(node *ploc), where ploc is the node we no longer need in the linked list. And yes, it is similar to doing free or delete on ploc. We can either directly do it in the current function or do it in a separate function like recycle.