Make use of a local pool to avoid over-memory usage

pull/32/head
Ludovic Marcotte 2014-04-04 16:53:58 -04:00
parent 2f565d2ec9
commit 846212336a
1 changed files with 10 additions and 1 deletions

View File

@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SOGoMailObject+ActiveSync.h" #include "SOGoMailObject+ActiveSync.h"
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h> #import <Foundation/NSCalendarDate.h>
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h> #import <Foundation/NSException.h>
@ -479,7 +480,9 @@ struct GlobalObjectId {
// //
- (NSString *) activeSyncRepresentationInContext: (WOContext *) _context - (NSString *) activeSyncRepresentationInContext: (WOContext *) _context
{ {
NSAutoreleasePool *pool;
NSData *d, *globalObjId; NSData *d, *globalObjId;
NSArray *attachmentKeys;
NSMutableString *s; NSMutableString *s;
id value; id value;
@ -670,6 +673,10 @@ struct GlobalObjectId {
// Body - namespace 17 // Body - namespace 17
preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue]; preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue];
// Make use of a local pool here as _preferredBodyDataUsingType:nativeType: will consume
// a significant amout of RAM and file descriptors
pool = [[NSAutoreleasePool alloc] init];
nativeBodyType = 1; nativeBodyType = 1;
d = [self _preferredBodyDataUsingType: preferredBodyType nativeType: &nativeBodyType]; d = [self _preferredBodyDataUsingType: preferredBodyType nativeType: &nativeBodyType];
@ -710,8 +717,10 @@ struct GlobalObjectId {
[s appendString: @"</Body>"]; [s appendString: @"</Body>"];
} }
DESTROY(pool);
// Attachments -namespace 16 // Attachments -namespace 16
NSArray *attachmentKeys = [self fetchFileAttachmentKeys]; attachmentKeys = [self fetchFileAttachmentKeys];
if ([attachmentKeys count]) if ([attachmentKeys count])
{ {
int i; int i;