Comments (4)
thanks! that LIST_FREE just frees the node itself which holds the value
from list.
Thanks for getting back to me so fast.
I think I understand. You need the the call to if (self->free) self->free(curr->val);
because the value associated with a node (its data) is stored separately in memory? So freeing the node only frees the struct? If you didn't have if (self->free) self->free(curr->val);
then you'd have a memory leak?
from list.
yup that's correct, the general rule is every allocation needs a mirrored free()
from list.
Awesome, very cool.
I've always known that manual memory management almost always becomes a headache. But I'm only now beginning to get the chance to work with C on a level that requires dynamic memory from the heap (malloc/free). I'm starting to see now why garbage collection is so popular. :-)
Because list_node_new()
accepts a void* to a val somewhere in memory, it's your library's responsibility to ensure the memory created (no matter who allocated and passed it in) gets properly free()'d when the list is no longer needed.
Thanks again for the assistance.
from list.
Related Issues (17)
- Default free function HOT 1
- list_t->free dox
- Add support for circular linked lists
- malloc free HOT 4
- Function pointers HOT 3
- after list_remove item is still available HOT 1
- Debian package HOT 1
- list_remove should check node to NULL HOT 3
- Configuration header for list.h HOT 3
- Error freeing items with link_remove() HOT 1
- shared library HOT 5
- Install with less generic names? HOT 4
- New release for 0.4.0 HOT 4
- Why not add LIST_FREE(node) in functions list_rpop() or list_lp()? HOT 1
- Detecting loops in linked lists HOT 1
- warning: comparison of integers of different signs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from list.