Questions tagged [memory-management]

For questions related to managing memory in programming languages, whether manually or automatically.

Filter by
Sorted by
Tagged with
8 votes
1 answer

What was the rationale for making realloc(ptr, 0) have UB in C23

This is the first breaking change that C made, which was making realloc(ptr, 0) have UB instead of being roughly equivalent to ...
user1345541's user avatar
2 votes
1 answer

Are there languages making addresses to have other significant meaning?

Some examples: To support checking whether an object is of a subclass of a specific class in constant time, in a language using single inheritance, the compiler could arrange the vtables of classes ...
user23013's user avatar
  • 2,010
16 votes
6 answers

Possible to mix garbage collection and manual memory management?

Do you think it is possible to have a language that uses garbage collection (GC) by default, but allows you take more control with manual memory management like C++ or Rust, in areas of the software ...
Rob N's user avatar
  • 1,043
2 votes
1 answer

X86-64 Assembly for Recursive Functions

A compiler I'm writing generates the following x86-64 assembly (AT&T syntax) for a recursive factorial function. I convert the assembly into an ELF executable using ...
Veera Sivarajan's user avatar
11 votes
2 answers

Why did Objective-C remove `NSZone`?

NSZone is a type representing a memory allocation. NSObject implements the allocWithZone: ...
Bbrk24's user avatar
  • 8,553
6 votes
3 answers

Why might a language avoid reallocation?

In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
user16217248's user avatar
  • 7,245
2 votes
1 answer

Memory layout from a native class

I think there are languages where most of the standard library is written in themselves, however with most things marked as native or ...
Hydroper's user avatar
  • 749
2 votes
4 answers

Approaches for implementing weak references

How can weak references (weakrefs) be implemented, and how do the different approaches compare? The most important considerations for implementing weakrefs are: Safety ─ a weakref shouldn't allow ...
kaya3's user avatar
  • 16.3k
12 votes
2 answers

Could ownership be inferred?

Rust famously has the concept of ownership vs. borrowing as part of its type system. This allows some level of automatic memory management ─ that is, heap allocations are freed when their owner goes ...
kaya3's user avatar
  • 16.3k
12 votes
3 answers

Is it possible to extend C to have the Rust concept of ownership for memory safety?

Rust has a number of memory safety features. Is it possible to extend or enhance C or C++ to also provide similar memory safety features instead of using workarounds such as the Valgrind tool suite?
James Risner's user avatar