[futurebasic] Calling MallocDebug experts

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2005 : Group Archive : Group : All Groups

From: Bernie <fblist@...>
Date: Wed, 1 Jun 2005 12:07:26 +0100
Dear MallocDebuggers,

I'm trying to get into the habit of Mallocing my app every time I add  
a chunk of code.

After installing the nav stuff that I've been boring you all with,  
MallocDebug is showing a memory leak. I'm still not that familiar  
with MD but it looks like it could be an OS problem. Any chance  
someone can run this through MD and confirm if it's my code or the OS  
that's causing the leak?

Note: After launching the built app in Malloc, do a cmd-O to bring up  
the open dialog then click cancel.

TIA
Bernie



'----------

'~'A
'                             Runtime : Rntm Appearance.Incl
'                                 CPU : Carbon
'                          CALL Req'd : Off
'~'B

include "LSInfo.incl"

_typeFSRef = _"fsrf"

toolbox fn UTTypeCreatePreferredIdentifierForTag( CFStringRef  
inTagClass, CFStringRef inTag, CFStringRef inConformingToUTI ) =  
CFStringRef
toolbox fn UTCreateStringForOSType( OSType inOSType ) = CFStringRef
toolbox fn UTTypeConformsTo( CFStringRef inUTI1, CFStringRef inUTI2 )  
= Boolean
toolbox fn AECoerceDesc( const AEDesc * theAEDesc, DescType toType,  
AEDesc * result ) = OSErr

long if 0
"NavFilterProc"
enterproc fn MyFilterProc( theItem as ^AEDesc, info as  
^NavFileOrFolderInfo, callbackUD as Ptr, filterMode as UInt32 )
dim as LSItemInfoRecord    itemInfo
dim as FSRef               fsRef
dim as CFStringRef         itemUTI, typeString
dim as OSErr               err
dim as Boolean             display

display = _true
long if ( info.isFolder == _false )
err = fn AECoerceDesc( #theItem, _typeFSRef, #theItem )
long if fn AEGetDescData( #theItem, @fsRef, sizeof( FSRef ) ) == _noErr
itemInfo.extension = 0

long if fn LSCopyItemInfoForRef( @fsRef,  
_kLSRequestExtension_kLSRequestTypeCreator, @itemInfo ) == _noErr
itemUTI = 0

long if ( itemInfo.filetype )
typeString = fn UTCreateStringForOSType( itemInfo.filetype )
itemUTI = fn UTTypeCreatePreferredIdentifierForTag( fn CFSTR 
( "public.filename-extension" ), typeString, _nil )
CFRelease( typeString )
xelse
itemUTI = fn UTTypeCreatePreferredIdentifierForTag( fn CFSTR 
( "public.filename-extension" ), itemInfo.extension, _nil )
CFRelease( itemInfo.extension )
end if

long if ( itemUTI )
display = fn UTTypeConformsTo( itemUTI, fn CFSTR( "public.text" ) )
CFRelease( itemUTI )
end if
end if
end if
end if
exitproc = display
end if


long if 0
"NavEventProc"
enterproc fn NavEventProc( callBackSelector as  
NavEventCallbackMessage, callBackParms as ^NavCBRecPtr, userData as  
Ptr )
dim as Str255 s
dim as long            @ keyword, actualType, actualSize
dim as long              action
dim as NavReplyRecord  @ reply
dim as FSSpec          @ appSpec
dim as FSRef           @ ref
dim as OSStatus          ignore

select callBackSelector
case _kNavCBUserAction
action = fn NavDialogGetUserAction( callBackParms.context )
select action
case _kNavUserActionOpen
ignore = fn NavDialogGetReply( callBackParms.context, reply )
ignore = fn AEGetNthPtr( reply.selection, 1, _typeFSS, keyword,  
actualType, appSpec, sizeof( FSSpec ), actualSize )

// open file

ignore = fn NavDisposeReply( reply )

case _kNavUserActionSaveAs
ignore = fn NavDialogGetReply( callBackParms.context, reply )
ignore = fn AEGetNthPtr( reply.selection, 1, _typeFSS, keyword,  
actualType, appSpec, sizeof( FSSpec ), actualSize )

// save file

ignore = fn NavDisposeReply( reply )

end select

case _kNavCBTerminate
if ( callBackParms.context ) then NavDialogDispose 
( callBackParms.context )

end select
exitproc
end if


local fn FileOpenSave( save as Boolean )
'~'1
dim as NavDialogCreationOptions   options
dim as NavDialogRef             @ dialogRef
dim as OSStatus                   ignore
begin globals
dim as proc                       sNavEventUPP // 'static' var
dim as proc                       sNavFilterUPP // 'static' var
end globals
if ( sNavEventUPP == 0  ) then sNavEventUPP  = fn NewNavEventUPP 
( [proc "NavEventProc"  + _FBprocToProcPtrOffset] )
if ( sNavFilterUPP == 0 ) then sNavFilterUPP = fn NewNavEventUPP 
( [proc "NavFilterProc" + _FBprocToProcPtrOffset] )

ignore = fn NavGetDefaultDialogCreationOptions( options )
long if save
options.windowTitle = fn CFSTR( "Save Project" )
ignore = fn NavCreatePutFileDialog( options, 0, 0, sNavEventUPP, #0,  
@dialogRef )
xelse
options.windowTitle = fn CFSTR( "Open Project" )
ignore = fn NavCreateGetFileDialog( options, 0, sNavEventUPP, 0,  
sNavFilterUPP, #0, @dialogRef )
end if
ignore = fn NavDialogRun( dialogRef )
end fn


local fn DoMenu
if ( menu( _menuID) == 1 ) and ( menu( _itemID ) == 1 ) then fn  
FileOpenSave( _false )
menu
end fn

menu 1, 0, _enable, "File"
menu 1, 1, _enable, "Open/O"

on menu fn DoMenu

do
HandleEvents
until gFBQuit
'----------