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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:29:32+00:00 2026-06-07T00:29:32+00:00

In Cocoa, I get the array of windows of an app using the following

  • 0

In Cocoa, I get the array of windows of an app using the following code:

CFArrayRef windows;
AXError gettingWindowsResult = AXUIElementCopyAttributeValues(app, (CFStringRef)NSAccessibilityWindowsAttribute, 0, 999, &windows);

Then I check some values of those windows and keep the AXUIElementRef of one of them in a variable of my class. At the end of the method, I release the CFArrayRef to make sure I don’t have any memory leaks:

if (windows != nil)
{
    CFRelease(windows);
}

Though this makes it so that when I try to use the window I kept, I get a bad access error. So my question: is it necessary that I release the array? And if so, how do I prevent the bad access error?

  • 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-07T00:29:33+00:00Added an answer on June 7, 2026 at 12:29 am

    Why not make a retained copy of the “AXUIElementRef” of the one element you want to keep?

    To do this, figure out the index of the element you want to keep, and then make another call to the “AXUIElementCopyAttributeValues” function, only this time just pass the index for the element you desire and a “maxValue” of 1. For example, for the element at position 26:

    AXError gettingWindowsResult = AXUIElementCopyAttributeValues(app, (CFStringRef)NSAccessibilityWindowsAttribute, 26, 1, &arrayOfOne);
    

    Then you can safely call “CFRelease” on the “windows” array.

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

Sidebar

Related Questions

I am writing a Cocoa App to display a 2-d floating array. I now
I am new to cocoa programming, Using the below code I want to show
How can I get the current battery level using the Cocoa framework running with
I'm using NSTask in my Cocoa APP , and I need to be able
I'm trying to get my Gmail unread email count using Cocoa (Mac) and the
I've been trying to get some example code interfaced with a Cocoa interface(It had
If I get an error code result from a Cocoa function, is there any
I'm trying to use some Apple Events in my Cocoa project to get access
I'm trying to get 4x6 cards to print in Cocoa (story cards). I have
In Objective-c/Cocoa, how do I get the icon that Finder uses for the desktop

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.