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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:03:25+00:00 2026-06-09T20:03:25+00:00

How can I implement a class/object that has a reference to a bunch of

  • 0

How can I implement a class/object that has a reference to a bunch of non-retained id objects?

I want something similar to what UIControl/NSControl has: addTarget:(id)target action:(SEL)action ...; (in my case, though, I don’t need the UIControlEvents part). I want to use this target/action pattern (and preferably stay away from the delegate pattern) but for that I need to make sure the targets added to my object are not retained or retain cycles might happen.

I think implementing my own array using malloc/free to make sure targets are not retained would be one solution, but all this hassle smells like there is already a solution implemented somewhere. Is there?

  • 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-09T20:03:27+00:00Added an answer on June 9, 2026 at 8:03 pm

    On OS X you can create an NSPointerArray that will keep weak references to its objects with +[NSPointerArray weakObjectsPointerArray], or (if you want a dictionary) an NSMapTable which allows either or both of the keys and values to be held weakly.

    Neither of those are available currently on iOS, but Core Foundation is. On either OS X or iOS you can use CFArray or CFDictionary, passing NULL for the callbacks to make the collection do no memory management of its contained objects. Be warned that if you try to use these as if they were their toll-free bridged Cocoa counterparts, the collection will not honor your non-retaining/non-copying desire. You’ll have to use the CF functions to interact with them (or whip up a wrapper class).

    You can also wrap your objects in NSValues, using valueWithNonretainedObject:, and put those into a Cocoa collection (NSDictionary/NSarray). The collection will own the value, but the value will not own its object.

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

Sidebar

Related Questions

I want to implement a class which can be used by two classes of
What Swing class can I use to implement something like this? Add To List
The goal is to implement a web application that can execute methods of .class
How many interfaces can a class file implement? Is there a limit on the
interfaces provide a useful abstraction capability. One can have a class Foo implement some
How do i implement a java comparator class which can sort the order of
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
I am developing an internal class that implements an internal interface. Can anyone explain
In Effective Java, the author states that: If a class implements Cloneable, Object's clone
I have a class that represents the state of the world. The class has

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.