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 736389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:35:58+00:00 2026-05-14T07:35:58+00:00

On a iPhone app, I need to send a jpg by mail with a

  • 0

On a iPhone app, I need to send a jpg by mail with a maximum size of 300Ko (I don’t no the maximum size mail.app can have, but it’s another problem). To do that, I’m trying to decrease quality until obtain an image under 300Ko.

In order to obtain the good value of the quality (compressionLevel) who give me a jpg under 300Ko, I have made the following loop.
It’s working, but each time time the loop is executed, the memory increase of the size of the original size of my jpg (700Ko) despite the “[tmpImage release];”.

float compressionLevel = 1.0f;
int size = 300001;
while (size  > 300000) {
    UIImage *tmpImage =[[UIImage alloc] initWithContentsOfFile:[self fullDocumentsPathForTheFile:@"imageToAnalyse.jpg"]];
    size = [UIImageJPEGRepresentation(tmpImage, compressionLevel) length];
    [tmpImage release];
        //In the following line, the 0.001f decrement is choose just in order test the increase of the memory  
    //compressionLevel = compressionLevel - 0.001f;
    NSLog(@"Compression: %f",compressionLevel);
} 

Any ideas about how can i get it off, or why it happens?
thanks

  • 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-14T07:35:58+00:00Added an answer on May 14, 2026 at 7:35 am

    At the very least, there’s no point in allocating and releasing the image on every trip through the loop. It shouldn’t leak memory, but it’s unnecessary, so move the alloc/init and release out of the loop.

    Also, the data returned by UIImageJPEGRepresentation is auto-released, so it’ll hang around until the current release pool drains (when you get back to the main event loop). Consider adding:

    NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];
    

    at the top of the loop, and

    [p drain] 
    

    at the end. That way you’ll not be leaking all of the intermediate memory.

    And finally, doing a linear search for the optimal compression setting is probably pretty inefficient. Do a binary search instead.

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

Sidebar

Related Questions

I need to send an email from my iPhone app but the name of
I want to make a iPhone app but I need to now how you
I need to have a few buttons in my iPhone app (which may be
I need to send some details to a server from my iphone app. I
I am writing an iPhone App and I need to securely send an XML
In an iPhone app I'm developing, I need to send an email programmatically (read,
I am developing an app where iphone and android phones need to send requests
I need to use Notifications via APNS in my iPhone App. But as I
I'm developing a iPhone app and need to send it to my client. In
I have almost finished my iPhone app and would like to send it in

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.