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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:57:31+00:00 2026-06-10T23:57:31+00:00

Part of my program reads directory, then calculates hash for each file in folder.

  • 0

Part of my program reads directory, then calculates hash for each file in folder. Each file loads to memory and I don`t know how to release it. I read a lot of topics here but can not find right answer. Could someone help?

#import "MD5.h"
...

NSFileManager * fileMan = [[NSFileManager alloc] init];
NSArray * files = [fileMan subpathsOfDirectoryAtPath:fullPath error:nil];

if (files) 
{
  for(int index=0;index<files.count;index++) 
  {
    NSString * file = [files objectAtIndex:index];
    NSString * fullFileName = [fullPath stringByAppendingString:file];
    if( [[file pathExtension] compare: @"JPG"] == NSOrderedSame )
    {
      NSData * nsData = [NSData dataWithContentsOfFile:fullFileName];
      if (nsData)
      {
        [names addObject:[NSString stringWithString:[nsData MD5]]];
         NSLog(@"%@", [nsData MD5]);       
      }
    }
  }
}

And MD5.m

#import <CommonCrypto/CommonDigest.h>

@implementation NSData(MD5)

- (NSString*)MD5
{
    // Create byte array of unsigned chars
  unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];

    // Create 16 byte MD5 hash value, store in buffer
    CC_MD5(self.bytes, (uint)self.length, md5Buffer);

    // Convert unsigned char buffer to NSString of hex values
  NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
  for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) 
        [output appendFormat:@"%02x",md5Buffer[i]];

  return output;
}

@end
  • 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-06-10T23:57:32+00:00Added an answer on June 10, 2026 at 11:57 pm

    If you are using ARC then the data will be automatically deallocated at some point after the last reference to it goes away. In your case this will be when it goes out of scope at the end of the if statement.

    In short, the code you have there is OK.

    There is one thing, some of the memory used when creating the data object might be held in an autorelease pool. It won’t go away until you are back in the event loop. If you wrap the code in an @autoreleasepool { ... } block, that problem will go away.

    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html

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

Sidebar

Related Questions

I want to automate a program that reads a file, processes it and then
We have a part of our program which can save a diagnostic file for
I'm trying to create a program that reads a .docx file and posts it
My program reads a file, interleaving it as below: The file to be read
I need a little program which: Reads natural number n then reads n real
I recently built a program that parses a remote file from \some_server\c$\directory\file.xls and it
Hello I am new to assembly and I'm struggling to get a two-part program
As part of the program that I am writing I need it to: Compare
Say one part of a program writes some stuff to a socket and another
For a part of a program i need the following 2 methods. The first

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.