• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString and UIWebView load
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString and UIWebView load


  • Subject: Re: NSString and UIWebView load
  • From: Dragos Ionel <email@hidden>
  • Date: Sat, 12 Sep 2009 16:54:56 -0400

I still cannot figure this out, so any help would be kind appreciated.
I followed the debugging steps from
here<http://www.corbinstreehouse.com/blog/index.php/2007/10/instruments-on-leopard-how-to-debug-those-random-crashes-in-your-cocoa-app/>and
here is what I obtained:

Code except:

.h file:
...

@interface DetailViewController : UIViewController <UIWebViewDelegate>

...

.m file:


- (void) webViewDidFinishLoad:(UIWebView *)sender {

NSLog(@"Enter webViewDidFinishLoad");


 if(saveView==YES){

//add a new page to the scroll view

NSLog(@"save view for page %d", crtPage);

 NSString* htmlTemplate = @"<html><body><div align='justify'><font
face='American Typewriter' color='black'
size='2'>@text</font></div></body></html>";

NSString * htmlContentTemp = [aChapter.content substringWithRange:
NSMakeRange(startPos,crtPos-startPos)];

htmlContentTemp = [htmlContentTemp stringByReplacingOccurrencesOfString:@"~"
withString:@"<br/>&nbsp;&nbsp;"];

htmlContentTemp = [htmlTemplate stringByReplacingOccurrencesOfString:
@"@text" withString:htmlContentTemp];

 UIWebView* newWebView = [[UIWebView alloc] initWithFrame:CGRectMake(5,5,310
,400)];

[newWebView loadHTMLString:htmlContentTemp baseURL:[NSURL URLWithString:@""
]];

[scrollView addSubview:newWebView];

[newWebView release];

}

}


The log shows me that:

12/09/09 4:22:42 PM alice[1572] *** -[CFString _createSubstringWithRange:]:
message sent to deallocated instance *0x7495ac0*

that corresponds to:

# Category Event Type Timestamp Address Size Responsible Library Responsible
Caller
342 CFString CFRelease 00:20.347 *0x7495ac0* *0* UIKit *-[UIWebDocumentView
loadHTMLString:baseURL:*]



So making a long story short,

when I launch
*[newWebView **loadHTMLString**:htmlContentTemp **baseURL**:[**NSURL** **
URLWithString**:**@""**]];*

the string *htmlContentTemp* gets deallocated before the *UIWebView* loaded
the content

Any suggestion how I can prevent that?

Thanks a lot,
Dragos



On Fri, Sep 11, 2009 at 10:10 PM, Andrew Farmer <email@hidden> wrote:

> On 11 Sep 2009, at 06:59, Dragos Ionel wrote:
>
>> Is the following code supposed to run correctly?
>>
>> NSString* *htmlContent* = ...;// very long html content
>>
>> UIWebView* webView = [[UIWebView alloc] initWithFrame:...];
>>
>> [webView  loadHTMLString:*htmlContent* baseURL:...]; //assume this will
>> take
>> some time
>>
>> *htmlContent* = @"different text";
>>
>> My question is if the memory space for *htmlContent* will be preserved
>> until
>> the webView finishes loading it, considering the fact that it will run in
>> a
>> different thread.
>>
>
> Assigning a new value to a NSString * pointer does not mutate the original
> string.
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSString and UIWebView load
      • From: Jens Alfke <email@hidden>
References: 
 >NSString and UIWebView load (From: Dragos Ionel <email@hidden>)
 >Re: NSString and UIWebView load (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: Retaining a NSURL and retaining its -path
  • Next by Date: Re: Retaining a NSURL and retaining its -path
  • Previous by thread: Re: NSString and UIWebView load
  • Next by thread: Re: NSString and UIWebView load
  • Index(es):
    • Date
    • Thread