Commit 204ee57f authored by Jan Djärv's avatar Jan Djärv

Fix biggest memory leaks in NS-port. More remain.

* emacs.c (ns_pool): New variable.
(main): Assign ns_pool.
(Fkill_emacs): Call ns_release_autorelease_pool.

* nsfns.m (x_set_background_color): Assign return value from
ns_index_color to face-background instead of NSColor*.
(ns_implicitly_set_icon_type): Fix indentation.
Change assignment in for loop to comparison.

* nsfont.m (ns_spec_to_descriptor): Fix indentation,
autorelease fdesc, release fdAttrs and tdict.
(ns_get_covering_families): Release charset.
(ns_findfonts): Release NSFontDescriptor created with new.
(ns_uni_to_glyphs): Fix indentation.
(setString): Release attrStr before assigning new value.

* nsmenu.m (ns_update_menubar): Call free_menubar_widget_value_tree
before returning.

* nsterm.m (x_free_frame_resources): Release
f->output_data.ns->miniimage
(ns_index_color): Fix indentation.  Do not retain
color_table->colors[i].
parent bc86f573
2011-12-21 Jan Djärv <jan.h.d@swipnet.se>
* nsterm.m (x_free_frame_resources): Release
f->output_data.ns->miniimage
(ns_index_color): Fix indentation. Do not retain
color_table->colors[i].
* nsmenu.m (ns_update_menubar): Call free_menubar_widget_value_tree
before returning.
* nsfns.m (x_set_background_color): Assign return value from
ns_index_color to face-background instead of NSColor*.
(ns_implicitly_set_icon_type): Fix indentation.
Change assignment in for loop to comparison.
* emacs.c (ns_pool): New variable.
(main): Assign ns_pool.
(Fkill_emacs): Call ns_release_autorelease_pool.
* nsfont.m (ns_spec_to_descriptor): Fix indentation,
autorelease fdesc, release fdAttrs and tdict.
(ns_get_covering_families): Release charset.
(ns_findfonts): Release NSFontDescriptor created with new.
(ns_uni_to_glyphs): Fix indentation.
(setString): Release attrStr before assigning new value.
2011-12-18 Jan Djärv <jan.h.d@swipnet.se>
* nsmenu.m (NSMenuDidBeginTrackingNotification): Declare if OSX < 10.5
......
......@@ -321,6 +321,12 @@ static void (*fatal_error_signal_hook) (void);
pthread_t main_thread;
#endif
#ifdef HAVE_NS
/* NS autrelease pool, for memory management. */
static void *ns_pool;
#endif
/* Handle bus errors, invalid instruction, etc. */
#ifndef FLOAT_CATCH_SIGILL
......@@ -1318,7 +1324,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
= argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args);
#ifdef HAVE_NS
ns_alloc_autorelease_pool ();
ns_pool = ns_alloc_autorelease_pool ();
if (!noninteractive)
{
#ifdef NS_IMPL_COCOA
......@@ -2015,6 +2021,10 @@ all of which are called before Emacs is actually killed. */)
shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
#ifdef HAVE_NS
ns_release_autorelease_pool (ns_pool);
#endif
/* If we have an auto-save list file,
kill it because we are exiting Emacs deliberately (not crashing).
Do it after shut_down_emacs, which does an auto-save. */
......
......@@ -394,9 +394,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
if (face)
{
col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
face->background
= (EMACS_UINT) [[col colorWithAlphaComponent: alpha] retain];
[col release];
face->background = ns_index_color
([col colorWithAlphaComponent: alpha], f);
update_face_from_frame_parameter (f, Qbackground_color, arg);
}
......@@ -770,7 +769,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
{
Lisp_Object tem;
EmacsView *view = FRAME_NS_VIEW (f);
id image =nil;
id image = nil;
Lisp_Object chain, elt;
NSAutoreleasePool *pool;
BOOL setMini = YES;
......@@ -797,7 +796,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
}
for (chain = Vns_icon_type_alist;
(image = nil) && CONSP (chain);
image == nil && CONSP (chain);
chain = XCDR (chain))
{
elt = XCAR (chain);
......
......@@ -126,8 +126,8 @@ static void ns_glyph_metrics (struct nsfont_info *font_info,
/* Converts FONT_WEIGHT, FONT_SLANT, FONT_WIDTH, plus family and script/lang
to NSFont descriptor. Information under extra only needed for matching. */
#define STYLE_REF 100
static NSFontDescriptor
*ns_spec_to_descriptor(Lisp_Object font_spec)
static NSFontDescriptor *
ns_spec_to_descriptor (Lisp_Object font_spec)
{
NSFontDescriptor *fdesc;
NSMutableDictionary *fdAttrs = [NSMutableDictionary new];
......@@ -152,8 +152,14 @@ static void ns_glyph_metrics (struct nsfont_info *font_info,
[fdAttrs setObject: tdict forKey: NSFontTraitsAttribute];
fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs];
if (family != nil)
if (family != nil)
{
fdesc = [fdesc fontDescriptorWithFamily: family];
[fdesc autorelease];
}
[fdAttrs release];
[tdict release];
return fdesc;
}
......@@ -469,6 +475,7 @@ but also for ascii (which causes unnecessary font substitution). */
if ([families count] > 0 || pct < 0.05)
break;
}
[charset release];
}
#ifdef NS_IMPL_COCOA
if ([families count] == 0)
......@@ -536,12 +543,14 @@ but also for ascii (which causes unnecessary font substitution). */
family = [fdesc objectForKey: NSFontFamilyAttribute];
if (family != nil && !foundItal && XINT (Flength (list)) > 0)
{
NSFontDescriptor *sDesc = [[[NSFontDescriptor new]
fontDescriptorWithSymbolicTraits: NSFontItalicTrait]
fontDescriptorWithFamily: family];
NSFontDescriptor *s1 = [NSFontDescriptor new];
NSFontDescriptor *sDesc
= [[s1 fontDescriptorWithSymbolicTraits: NSFontItalicTrait]
fontDescriptorWithFamily: family];
list = Fcons (ns_descriptor_to_entity (sDesc,
AREF (font_spec, FONT_EXTRA_INDEX),
"synthItal"), list);
[s1 release];
}
/* Return something if was a match and nothing found. */
......@@ -1293,7 +1302,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
abort ();
/* create a string containing all Unicode characters in this block */
for (idx = block<<8, i =0; i<0x100; idx++, i++)
for (idx = block<<8, i = 0; i < 0x100; idx++, i++)
if (idx < 0xD800 || idx > 0xDFFF)
unichars[i] = idx;
else
......@@ -1309,7 +1318,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
/*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
NSUInteger gInd =0, cInd =0;
NSUInteger gInd = 0, cInd = 0;
[glyphStorage setString: allChars font: font_info->nsfont];
[glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
......@@ -1317,7 +1326,7 @@ WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
glyphIndex: &gInd characterIndex: &cInd];
#endif
glyphs = font_info->glyphs[block];
for (i =0; i<0x100; i++, glyphs++)
for (i = 0; i < 0x100; i++, glyphs++)
{
#ifdef NS_IMPL_GNUSTEP
g = unichars[i];
......@@ -1425,6 +1434,8 @@ - (void) dealloc
- (void) setString: (NSString *)str font: (NSFont *)font
{
[dict setObject: font forKey: NSFontAttributeName];
if (attrStr != nil)
[attrStr release];
attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict];
maxChar = [str length];
maxGlyph = 0;
......
......@@ -404,6 +404,7 @@
items = FRAME_MENU_BAR_ITEMS (f);
if (NILP (items))
{
free_menubar_widget_value_tree (first_wv);
[pool release];
UNBLOCK_INPUT;
return;
......@@ -431,6 +432,7 @@
if (i == n)
{
free_menubar_widget_value_tree (first_wv);
[pool release];
UNBLOCK_INPUT;
return;
......
......@@ -1158,6 +1158,9 @@ Free a pool and temporary objects it refers to (callable from C)
xfree (f->output_data.ns);
if (f->output_data.ns->miniimage != nil)
[f->output_data.ns->miniimage release];
[[view window] close];
[view release];
......@@ -1351,7 +1354,7 @@ Free a pool and temporary objects it refers to (callable from C)
{
struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
ptrdiff_t idx;
NSNumber *index;
ptrdiff_t i;
if (!color_table->colors)
{
......@@ -1364,21 +1367,13 @@ Free a pool and temporary objects it refers to (callable from C)
}
/* do we already have this color ? */
{
ptrdiff_t i;
for (i = 1; i < color_table->avail; i++)
{
if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
{
[color_table->colors[i] retain];
return i;
}
}
}
for (i = 1; i < color_table->avail; i++)
if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
return i;
if ([color_table->empty_indices count] > 0)
{
index = [color_table->empty_indices anyObject];
NSNumber *index = [color_table->empty_indices anyObject];
[color_table->empty_indices removeObject: index];
idx = [index unsignedLongValue];
}
......@@ -1411,20 +1406,20 @@ Free a pool and temporary objects it refers to (callable from C)
color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
if (idx <= 0 || idx >= color_table->size) {
message1("ns_free_indexed_color: Color index out of range.\n");
message1 ("ns_free_indexed_color: Color index out of range.\n");
return;
}
index = [NSNumber numberWithUnsignedInt: idx];
if ([color_table->empty_indices containsObject: index]) {
message1("ns_free_indexed_color: attempt to free already freed color.\n");
message1 ("ns_free_indexed_color: attempt to free already freed color.\n");
return;
}
color = color_table->colors[idx];
[color release];
color_table->colors[idx] = nil;
[color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]];
[color_table->empty_indices addObject: index];
/*fprintf(stderr, "color_table: FREED %d\n",idx);*/
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment