• 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: Problem Ejecting Discs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem Ejecting Discs


  • Subject: Re: Problem Ejecting Discs
  • From: Patrick Machielse <email@hidden>
  • Date: Tue, 25 Nov 2003 13:30:14 +0100

op 21-11-2003 18:09 schreef Shawn Erickson op email@hidden:

> On Nov 21, 2003, at 2:11 AM, Patrick Machielse wrote:
>
>> I have an NSImageView displaying a pdf located on a mounted CD. When I
>> try
>> to eject the CD using:
>>
>> [myImageView setImage:nil];
>> [[NSWorkspace sharedWorkspace]
>> unmountAndEjectDeviceAtPath:@"myPath"];
>>
>> It fails. Somehow the ImageView keeps the pdf file open on the device,
>> preventing a successful eject.

> How do you create the image that is shown in the NSImageView? How is it
> released? Is it released before you attempt your unmount? Need a little
> more information so I am going to assume some things...

Both for the NSImageView and the NSView I do the following:

// make pdfimagerep
NSString *pdfPath = @"path_to_file.pdf";
NSPDFImageRep *pdfRep = [NSPDFImageRep imageRepWithContentsOfFile:pdfPath];

// make image
NSImage *pdfImage = [[[NSImage alloc] init] autorelease];
[pdfImage addRepresentation:pdfRep];

// set image
[myImageView setImage:pdfImage];

The views then retain the NSImage object. In my NSView subclass the NSImage
is explicitely released during the [... setImage:nil] call. It seems
NSImageView only autoreleases in this accessor method.

> You could try using NSImage's setDataRetained:(bool) and set it to
> retain the data.

I tried this:

// make image
NSImage *pdfImage = [[[NSImage alloc] init] autorelease];
[pdfImage setDataRetained:YES];
[pdfImage addRepresentation:pdfRep];

But the NSImageView still won't budge. I have to wait for the event loop to
end, let NSAutoreleasePool do it's job (I guess...) and then try again.

> An alternative is to load the file data into an NSData object and use
> that object to construct the image.

I looked this up, and imageRepWithContentsOfFile: in my code does this
(create an NSData object) behind the scenes.

Thanks for your 'pointers',

Patrick
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Problem Ejecting Discs (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: Java3D in cocoa
  • Next by Date: Re: Java3D in cocoa
  • Previous by thread: Re: Problem Ejecting Discs
  • Next by thread: dealloc of App Contoller never gets called
  • Index(es):
    • Date
    • Thread