Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4018466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:59:11+00:00 2026-05-20T09:59:11+00:00

I often try to fix bugs that occur when I use my iphone for

  • 0

I often try to fix bugs that occur when I use my iphone for other memory hungry stuff and it needs to free some memory and thus unload some views from my app. I found this quite hard to simulate when I need it so I decided to make that will try to allocate as much memory as possible and force my tested app to release unused views etc.

I tried something simple as calling this every few hundred milliseconds but it for some reason didn’t do anything

[[NSData alloc] initWithBytes:malloc(2048 * 1024) length:2048 * 1024];

Instruments show that apps is getting bigger and bigger, far beyond memory capacity of iphone (hundreds of mbs allocated) but I don’t even get memory warning and it doesn’t affect other apps at all. Is there some safeguard that somehow prevents iphone app form doing something like this? Or is there some mistake in my assumptions about how iphone works?
How do you solve this problem when you face it?

EDIT: I am running my app on device, I wasn’t able to get my views unloaded on simulator even if I simulated memory warning (this sometimes work, but only rarely)

EDIT2: as bbum pointed out problem was indeed in virtual allocation, simple memset after allocation did the trick

void *data = malloc(1024 * 1024);
memset(data, 0, 1024 * 1024);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:59:12+00:00Added an answer on May 20, 2026 at 9:59 am

    Most likely, what is happening is a tricksy bit of virtual addressing behind your back.

    Namely, an application is free to reserve up to the full 4GB of 32-bit address space available to it (less than 4GB, really, because there is fragmentation caused by various system pieces).

    When you do malloc(REALLYBIGNUMBER), the system uses vm_allocate() to fulfill the request. The mach memory manager hands you back the addresses, but doesn’t actually back it with real memory (kinda like the US economy has tons of $$$ in the market not backed by any real asset).

    Physical memory will only be used when you write (or, technically, read) something to the memory. And it will only happen page by page.

    So, if you were to walk through the allocated buffer in strides of 4096 (page size) and write one byte, you’d quickly see real memory being consumed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often, programmers write code that generates other code. (The technical term is metaprogramming ,
I have often read that some programming languages are clear than others and I
Often I find myself interacting with files in some way but after writing the
Often, I found OutOfMemoryException on IBM Websphere Application Server. I think this exception occur
Often multiple applications share a large codebase of libraries that change often in development.
I analyze a VB.NET project and there are some objects (child MDI form) that
This is something that happens to me really often. I have a textfield in
I think that this problem occurs often on a web application development. But I'll
What are the most common/frequent memory leaks programmers use to run into when developing
i often use but i have this problem. if there is a whose action

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.